Skip to content

Commit d457dac

Browse files
Robert Lovearve-android
Robert Love
authored andcommitted
ashmem for 2.6.27.
Forward port of ashmem to 2.6.27. Signed-off-by: Robert Love <[email protected]> ashmem: Don't install fault handler for private mmaps. Ashmem is used to create named private heaps. If this heap is backed by a tmpfs file it will allocate two pages for every page touched. In 2.6.27, the extra page would later be freed, but 2.6.29 does not scan anonymous pages when running without swap so the memory is not freed while the file is referenced. This change changes the behavior of private ashmem mmaps to match /dev/zero instead tmpfs. Signed-off-by: Arve Hjønnevåg <[email protected]> ashmem: Add common prefix to name reported in /proc/pid/maps Signed-off-by: Arve Hjønnevåg <[email protected]> ashmem: don't require a page aligned size This makes ashmem more similar to shmem and mmap, by not requiring the specified size to be page aligned, instead rounding it internally as needed. Signed-off-by: Marco Nelissen <[email protected]>
1 parent 96b7efe commit d457dac

File tree

6 files changed

+738
-5
lines changed

6 files changed

+738
-5
lines changed

Diff for: include/linux/ashmem.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* include/linux/ashmem.h
3+
*
4+
* Copyright 2008 Google Inc.
5+
* Author: Robert Love
6+
*
7+
* This file is dual licensed. It may be redistributed and/or modified
8+
* under the terms of the Apache 2.0 License OR version 2 of the GNU
9+
* General Public License.
10+
*/
11+
12+
#ifndef _LINUX_ASHMEM_H
13+
#define _LINUX_ASHMEM_H
14+
15+
#include <linux/limits.h>
16+
#include <linux/ioctl.h>
17+
18+
#define ASHMEM_NAME_LEN 256
19+
20+
#define ASHMEM_NAME_DEF "dev/ashmem"
21+
22+
/* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */
23+
#define ASHMEM_NOT_PURGED 0
24+
#define ASHMEM_WAS_PURGED 1
25+
26+
/* Return values from ASHMEM_GET_PIN_STATUS: Is the mapping pinned? */
27+
#define ASHMEM_IS_UNPINNED 0
28+
#define ASHMEM_IS_PINNED 1
29+
30+
struct ashmem_pin {
31+
__u32 offset; /* offset into region, in bytes, page-aligned */
32+
__u32 len; /* length forward from offset, in bytes, page-aligned */
33+
};
34+
35+
#define __ASHMEMIOC 0x77
36+
37+
#define ASHMEM_SET_NAME _IOW(__ASHMEMIOC, 1, char[ASHMEM_NAME_LEN])
38+
#define ASHMEM_GET_NAME _IOR(__ASHMEMIOC, 2, char[ASHMEM_NAME_LEN])
39+
#define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t)
40+
#define ASHMEM_GET_SIZE _IO(__ASHMEMIOC, 4)
41+
#define ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned long)
42+
#define ASHMEM_GET_PROT_MASK _IO(__ASHMEMIOC, 6)
43+
#define ASHMEM_PIN _IOW(__ASHMEMIOC, 7, struct ashmem_pin)
44+
#define ASHMEM_UNPIN _IOW(__ASHMEMIOC, 8, struct ashmem_pin)
45+
#define ASHMEM_GET_PIN_STATUS _IO(__ASHMEMIOC, 9)
46+
#define ASHMEM_PURGE_ALL_CACHES _IO(__ASHMEMIOC, 10)
47+
48+
#endif /* _LINUX_ASHMEM_H */

Diff for: include/linux/mm.h

+1
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ extern void show_free_areas(void);
732732

733733
int shmem_lock(struct file *file, int lock, struct user_struct *user);
734734
struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags);
735+
void shmem_set_file(struct vm_area_struct *vma, struct file *file);
735736
int shmem_zero_setup(struct vm_area_struct *);
736737

737738
#ifndef CONFIG_MMU

Diff for: init/Kconfig

+9
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,15 @@ config SHMEM
964964
option replaces shmem and tmpfs with the much simpler ramfs code,
965965
which may be appropriate on small systems without swap.
966966

967+
config ASHMEM
968+
bool "Enable the Anonymous Shared Memory Subsystem"
969+
default n
970+
depends on SHMEM || TINY_SHMEM
971+
help
972+
The ashmem subsystem is a new shared memory allocator, similar to
973+
POSIX SHM but with different behavior and sporting a simpler
974+
file-based API.
975+
967976
config AIO
968977
bool "Enable AIO support" if EMBEDDED
969978
default y

Diff for: mm/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ obj-$(CONFIG_HUGETLBFS) += hugetlb.o
2424
obj-$(CONFIG_NUMA) += mempolicy.o
2525
obj-$(CONFIG_SPARSEMEM) += sparse.o
2626
obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o
27+
obj-$(CONFIG_ASHMEM) += ashmem.o
2728
obj-$(CONFIG_SLOB) += slob.o
2829
obj-$(CONFIG_COMPACTION) += compaction.o
2930
obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o

0 commit comments

Comments
 (0)