Swap over NFS -v18
Subsystems (22)
cover Swap over NFS -v18
Latest version of the swap over nfs work.
Patches are against: v2.6.26-rc8-mm1
I still need to write some more comments in the reservation code.
Pekka, it uses ksize(), please have a look.
This version also deals with network namespaces. Two things where I could do with some suggestsion:
- currently the sysctl code uses current->nrproxy.net_ns to obtain the current network namespace
- the ipv6 route cache code has some initialization order issues
Thanks,
Peter - who hopes we can someday merge this - Zijlstra
--
Documentation/filesystems/Locking | 22 + Documentation/filesystems/vfs.txt | 18 + Documentation/network-swap.txt | 270 +++++++++++++++++ drivers/net/bnx2.c | 8 drivers/net/e1000/e1000_main.c | 8 drivers/net/e1000e/netdev.c | 7 drivers/net/igb/igb_main.c | 8 drivers/net/ixgbe/ixgbe_main.c | 10 drivers/net/sky2.c | 16 - fs/Kconfig | 17 + fs/nfs/file.c | 24 + fs/nfs/inode.c | 6 fs/nfs/internal.h | 7 fs/nfs/pagelist.c | 8 fs/nfs/read.c | 21 - fs/nfs/write.c | 175 +++++++---- include/linux/buffer_head.h | 2 include/linux/fs.h | 9 include/linux/gfp.h | 3 include/linux/mm.h | 25 + include/linux/mm_types.h | 2 include/linux/mmzone.h | 6 include/linux/nfs_fs.h | 2 include/linux/pagemap.h | 5 include/linux/reserve.h | 146 +++++++++ include/linux/sched.h | 7 include/linux/skbuff.h | 46 ++ include/linux/slab.h | 24 - include/linux/slub_def.h | 8 include/linux/sunrpc/xprt.h | 5 include/linux/swap.h | 4 include/net/inet_frag.h | 7 include/net/netns/ipv6.h | 4 include/net/sock.h | 63 +++- include/net/tcp.h | 2 kernel/softirq.c | 3 mm/Makefile | 2 mm/internal.h | 10 mm/page_alloc.c | 207 +++++++++---- mm/page_io.c | 52 +++ mm/reserve.c | 594 ++++++++++++++++++++++++++++++++++++++ mm/slab.c | 135 ++++++++ mm/slub.c | 159 ++++++++-- mm/swap_state.c | 4 mm/swapfile.c | 51 +++ mm/vmstat.c | 6 net/Kconfig | 3 net/core/dev.c | 59 +++ net/core/filter.c | 3 net/core/skbuff.c | 147 +++++++-- net/core/sock.c | 129 ++++++++ net/ipv4/inet_fragment.c | 3 net/ipv4/ip_fragment.c | 89 +++++ net/ipv4/route.c | 72 ++++ net/ipv4/tcp.c | 5 net/ipv4/tcp_input.c | 12 net/ipv4/tcp_output.c | 12 net/ipv4/tcp_timer.c | 2 net/ipv6/af_inet6.c | 20 + net/ipv6/reassembly.c | 88 +++++ net/ipv6/route.c | 66 ++++ net/ipv6/tcp_ipv6.c | 17 - net/netfilter/core.c | 3 net/sctp/ulpevent.c | 2 net/sunrpc/sched.c | 9 net/sunrpc/xprtsock.c | 73 ++++ security/selinux/avc.c | 2 67 files changed, 2720 insertions(+), 314 deletions(-)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/30 swap over network documentation
Document describing the problem and proposed solution
--- Documentation/network-swap.txt | 270 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+)
Documentation/network-swap.txt new file +270 -0
@@ -0,0 +1,270 @@ + +Problem: + When Linux needs to allocate memory it may find that there is + insufficient free memory so it needs to reclaim space that is in + use but not needed at the moment. There are several options: + + 1/ Shrink a kernel cache such as the inode or dentry cache. This + is fairly easy but provides limited returns. + 2/ Discard 'clean' pages from the page cache. This is easy, and + works well as long as there are clean pages in the page cache. + Similarly clean 'anonymous' pages can be discarded - if there + are any. + 3/ Write out some dirty page-cache pages so that they become clean. + The VM limits the number of dirty page-cache pages to e.g. 40% + of available memory so that (among other reasons) a "sync" will + not take excessively long. So there should never be excessive + amounts of dirty pagecache. + Writing out dirty page-cache pages involves work by the + filesystem which may need to allocate memory itself. To avoid + deadlock, filesystems use GFP_NOFS when allocating memory on the + write-out path. When this is used, cleaning dirty page-cache + pages is not an option so if the filesystem finds that memory + is tight, another option must be found. + 4/ Write out dirty anonymous pages to the "Swap" partition/file. + This is the most interesting for a couple of reasons. + a/ Unlike dirty page-cache pages, there is no need to write anon + pages out unless we are actually short of memory. Thus they + tend to be left to last. + b/ Anon pages tend to be updated randomly and unpredictably, and + flushing them out of memory can have a very significant + performance impact on the process using them. This contrasts + with page-cache pages which are often written sequentially + and often treated as "write-once, read-many". + So anon pages tend to be left until last to be cleaned, and may + be the only cleanable pages while there are still some dirty + page-cache pages (which are waiting on a GFP_NOFS allocation). + +[I don't find the above wholly satisfying. There seems to be too much + hand-waving. If someone can provide better text explaining why + swapout is a special case, that would be great.] + +So we need to be able to write to the swap file/partition without +needing to allocate any memory ... or only a small well controlled +amount. + +The VM reserves a small amount of memory that can only be allocated +for use as part of the swap-out procedure. It is only available to +processes with the PF_MEMALLOC flag set, which is typically just the +memory cleaner. + +Traditionally swap-out is performed directly to block devices (swap +files on block-device filesystems are supported by examining the +mapping from file offset to device offset in advance, and then using +the device offsets to write directly to the device). Block devices +are (required to be) written to pre-allocate any memory that might be +needed during write-out, and to block when the pre-allocated memory is +exhausted and no other memory is available. They can be sure not to +block forever as the pre-allocated memory will be returned as soon as +the data it is being used for has been written out. The primary +mechanism for pre-allocating memory is called "mempools". + +This approach does not work for writing anonymous pages +(i.e. swapping) over a network, using e.g NFS or NBD or iSCSI. + + +The main reason that it does not work is that when data from an anon +page is written to the network, we must wait for a reply to confirm +the data is safe. Receiving that reply will consume memory and, +significantly, we need to allocate memory to an incoming packet before +we can tell if it is the reply we are waiting for or not. + +The secondary reason is that the network code is not written to use +mempools and in most cases does not need to use them. Changing all +allocations in the networking layer to use mempools would be quite +intrusive, and would waste memory, and probably cause a slow-down in +the common case of not swapping over the network. + +These problems are addressed by enhancing the system of memory +reserves used by PF_MEMALLOC and requiring any in-kernel networking +client that is used for swap-out to indicate which sockets are used +for swapout so they can be handled specially in low memory situations. + +There are several major parts to this enhancement: + +1/ page->reserve, GFP_MEMALLOC + + To handle low memory conditions we need to know when those + conditions exist. Having a global "low on memory" flag seems easy, + but its implementation is problematic. Instead we make it possible + to tell if a recent memory allocation required use of the emergency + memory pool. + For pages returned by alloc_page, the new page->reserve flag + can be tested. If this is set, then a low memory condition was + current when the page was allocated, so the memory should be used + carefully. (Because low memory conditions are transient, this + state is kept in an overloaded member instead of in page flags, which + would suggest a more permanent state.) + + For memory allocated using slab/slub: If a page that is added to a + kmem_cache is found to have page->reserve set, then a s->reserve + flag is set for the whole kmem_cache. Further allocations will only + be returned from that page (or any other page in the cache) if they + are emergency allocation (i.e. PF_MEMALLOC or GFP_MEMALLOC is set). + Non-emergency allocations will block in alloc_page until a + non-reserve page is available. Once a non-reserve page has been + added to the cache, the s->reserve flag on the cache is removed. + + Because slab objects have no individual state its hard to pass + reserve state along, the current code relies on a regular alloc + failing. There are various allocation wrappers help here. + + This allows us to + a/ request use of the emergency pool when allocating memory + (GFP_MEMALLOC), and + b/ to find out if the emergency pool was used. + +2/ SK_MEMALLOC, sk_buff->emergency. + + When memory from the reserve is used to store incoming network + packets, the memory must be freed (and the packet dropped) as soon + as we find out that the packet is not for a socket that is used for + swap-out. + To achieve this we have an ->emergency flag for skbs, and an + SK_MEMALLOC flag for sockets. + When memory is allocated for an skb, it is allocated with + GFP_MEMALLOC (if we are currently swapping over the network at + all). If a subsequent test shows that the emergency pool was used, + ->emergency is set. + When the skb is finally attached to its destination socket, the + SK_MEMALLOC flag on the socket is tested. If the skb has + ->emergency set, but the socket does not have SK_MEMALLOC set, then + the skb is immediately freed and the packet is dropped. + This ensures that reserve memory is never queued on a socket that is + not used for swapout. + + Similarly, if an skb is ever queued for delivery to user-space for + example by netfilter, the ->emergency flag is tested and the skb is + released if ->emergency is set. (so obviously the storage route may + not pass through a userspace helper, otherwise the packets will never + arrive and we'll deadlock) + + This ensures that memory from the emergency reserve can be used to + allow swapout to proceed, but will not get caught up in any other + network queue. + + +3/ pages_emergency + + The above would be sufficient if the total memory below the lowest + memory watermark (i.e the size of the emergency reserve) were known + to be enough to hold all transient allocations needed for writeout. + I'm a little blurry on how big the current emergency pool is, but it + isn't big and certainly hasn't been sized to allow network traffic + to consume any. + + We could simply make the size of the reserve bigger. However in the + common case that we are not swapping over the network, that would be + a waste of memory. + + So a new "watermark" is defined: pages_emergency. This is + effectively added to the current low water marks, so that pages from + this emergency pool can only be allocated if one of PF_MEMALLOC or + GFP_MEMALLOC are set. + + pages_emergency can be changed dynamically based on need. When + swapout over the network is required, pages_emergency is increased + to cover the maximum expected load. When network swapout is + disabled, pages_emergency is decreased. + + To determine how much to increase it by, we introduce reservation + groups.... + +3a/ reservation groups + + The memory used transiently for swapout can be in a number of + different places. e.g. the network route cache, the network + fragment cache, in transit between network card and socket, or (in + the case of NFS) in sunrpc data structures awaiting a reply. + We need to ensure each of these is limited in the amount of memory + they use, and that the maximum is included in the reserve. + + The memory required by the network layer only needs to be reserved + once, even if there are multiple swapout paths using the network + (e.g. NFS and NDB and iSCSI, though using all three for swapout at + the same time would be unusual). + + So we create a tree of reservation groups. The network might + register a collection of reservations, but not mark them as being in + use. NFS and sunrpc might similarly register a collection of + reservations, and attach it to the network reservations as it + depends on them. + When swapout over NFS is requested, the NFS/sunrpc reservations are + activated which implicitly activates the network reservations. + + The total new reservation is added to pages_emergency. + + Provided each memory usage stays beneath the registered limit (at + least when allocating memory from reserves), the system will never + run out of emergency memory, and swapout will not deadlock. + + It is worth noting here that it is not critical that each usage + stays beneath the limit 100% of the time. Occasional excess is + acceptable provided that the memory will be freed again within a + short amount of time that does *not* require waiting for any event + that itself might require memory. + This is because, at all stages of transmit and receive, it is + acceptable to discard all transient memory associated with a + particular writeout and try again later. On transmit, the page can + be re-queued for later transmission. On receive, the packet can be + dropped assuming that the peer will resend after a timeout. + + Thus allocations that are truly transient and will be freed without + blocking do not strictly need to be reserved for. Doing so might + still be a good idea to ensure forward progress doesn't take too + long. + +4/ low-mem accounting + + Most places that might hold on to emergency memory (e.g. route + cache, fragment cache etc) already place a limit on the amount of + memory that they can use. This limit can simply be reserved using + the above mechanism and no more needs to be done. + + However some memory usage might not be accounted with sufficient + firmness to allow an appropriate emergency reservation. The + in-flight skbs for incoming packets is one such example. + + To support this, a low-overhead mechanism for accounting memory + usage against the reserves is provided. This mechanism uses the + same data structure that is used to store the emergency memory + reservations through the addition of a 'usage' field. + + Before we attempt allocation from the memory reserves, we much check + if the resulting 'usage' is below the reservation. If so, we increase + the usage and attempt the allocation (which should succeed). If + the projected 'usage' exceeds the reservation we'll either fail the + allocation, or wait for 'usage' to decrease enough so that it would + succeed, depending on __GFP_WAIT. + + When memory that was allocated for that purpose is freed, the + 'usage' field is checked again. If it is non-zero, then the size of + the freed memory is subtracted from the usage, making sure the usage + never becomes less than zero. + + This provides adequate accounting with minimal overheads when not in + a low memory condition. When a low memory condition is encountered + it does add the cost of a spin lock necessary to serialise updates + to 'usage'. + + + +5/ swapon/swapoff/swap_out/swap_in + + So that a filesystem (e.g. NFS) can know when to set SK_MEMALLOC on + any network socket that it uses, and can know when to account + reserve memory carefully, new address_space_operations are + available. + "swapon" requests that an address space (i.e a file) be make ready + for swapout. swap_out and swap_in request the actual IO. They + together must ensure that each swap_out request can succeed without + allocating more emergency memory that was reserved by swapon. swapoff + is used to reverse the state changes caused by swapon when we disable + the swap file. + + +Thanks for reading this far. I hope it made sense :-) + +Neil Brown (with updates from Peter Zijlstra) + +
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/30 mm: gfp_to_alloc_flags()
In reply to Peter ZijlstraFactor out the gfp to alloc_flags mapping so it can be used in other places.
--- mm/internal.h | 10 +++++ mm/page_alloc.c | 95 +++++++++++++++++++++++++++++++------------------------- 2 files changed, 64 insertions(+), 41 deletions(-)
mm/internal.h +10 -0
@@ -187,6 +187,16 @@ static inline void free_page_mlock(struc#define __paginginit __init#endif +#define ALLOC_HARDER 0x01/* try to alloc harder */ +#define ALLOC_HIGH 0x02/* __GFP_HIGH set */ +#define ALLOC_WMARK_MIN 0x04/* use pages_min watermark */ +#define ALLOC_WMARK_LOW 0x08/* use pages_low watermark */ +#define ALLOC_WMARK_HIGH 0x10/* use pages_high watermark */ +#define ALLOC_NO_WATERMARKS 0x20/* don't check watermarks at all */ +#define ALLOC_CPUSET 0x40/* check for correct cpuset */ + +int gfp_to_alloc_flags (gfp_t gfp_mask); +/* Memory initialisation debug and verification */ enum mminit_level {MMINIT_WARNING ,
mm/page_alloc.c +54 -41
129 lines not on this page · raw message
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 02/30] mm: gfp_to_alloc_flags()
Quoted 7 lines · On Thursday July 24, [email protected] wrote:
Factor out the gfp to
alloc_flagsmapping so it can be used in other places.Signed-off-by Peter Zijlstra <[email protected]>--- mm/internal.h | 10 +++++ mm/page_alloc.c | 95 +++++++++++++++++++++++++++++++------------------------- 2 files changed, 64 insertions(+), 41 deletions(-)
This patch all looks "obviously correct" and a nice factorisation of code, except the last little bit:
Quoted 13 lines
mm/page_alloc.c +4
-0@@ -1618,6 +1627,10 @@ nofail_alloc:if (!wait) goto nopage; +/* Avoid recursion of direct reclaim */ +if (p->flags &PF_MEMALLOC ) + goto nopage; +cond_resched ();/* We now go into synchronous reclaim */ Signature · 1 line
--
I don't remember seeing it before (though my memory is imperfect) and it doesn't seem to fit with the rest of the patch (except spatially).
There is a test above for PF_MEMALLOC which will result in a "goto" somewhere else unless "in_interrupt()".
There is immediately above a test for "!wait".
So the only way this test can fire is when in_interrupt and wait. But if that happens, then the
might_sleep_if(wait)
at the top should have thrown a warning... It really shouldn't happen.
So it looks like it is useless code: there is already protection against recursion in this case.
Did I miss something?
If I did, maybe more text in the changelog entry (or the comment) would help.
Thanks,
NeilBrown
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 02/30] mm: gfp_to_alloc_flags()
Quoted 37 lines · Neil Brown
Quoted 7 lines · On Thursday July 24, [email protected] wrote:
Factor out the gfp to
alloc_flagsmapping so it can be used in other places.Signed-off-by Peter Zijlstra <[email protected]>--- mm/internal.h | 10 +++++ mm/page_alloc.c | 95 +++++++++++++++++++++++++++++++------------------------- 2 files changed, 64 insertions(+), 41 deletions(-)This patch all looks "obviously correct" and a nice factorisation of code, except the last little bit:
Quoted 13 lines
mm/page_alloc.c +4
-0@@ -1618,6 +1627,10 @@ nofail_alloc:if (!wait) goto nopage; +/* Avoid recursion of direct reclaim */ +if (p->flags &PF_MEMALLOC ) + goto nopage; +cond_resched ();/* We now go into synchronous reclaim */ Signature · 1 line
--I don't remember seeing it before (though my memory is imperfect) and it doesn't seem to fit with the rest of the patch (except spatially).
There is a test above for
PF_MEMALLOCwhich will result in a "goto" somewhere else unless "in_interrupt()".
There is immediately above a test for "!wait".
So the only way this test can fire is whenin_interruptand wait. But if that happens, then the
might_sleep_if(wait)
at the top should have thrown a warning... It really shouldn't happen.
Quoted 6 lines
So it looks like it is useless code: there is already protection against recursion in this case.
Did I miss something?
If I did, maybe more text in the changelog entry (or the comment) would help.
Ok, so the old code did:
if (((p->flags & PF_MEMALLOC) || ...) && !in_interrupt) {
....
goto nopage;
}which avoid anything that has PF_MEMALLOC set from entering into direct reclaim, right?
Now, the new code reads:
if (alloc_flags & ALLOC_NO_WATERMARK) {
}Which might be false, even though we have PF_MEMALLOC set - __GFP_NOMEMALLOC comes to mind.
So we have to stop that recursion from happening.
so we add:
if (p->flags & PF_MEMALLOC)
goto nopage;
Now, if it were done before the !wait check, we'd have to consider atomic contexts, but as those are - as you rightly pointed out - handled by the !wait case, we can plainly do this check.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 02/30] mm: gfp_to_alloc_flags()
Quoted 25 lines · On Tuesday August 12, [email protected] wrote:
Quoted 3 lines · Neil Brown
Did I miss something?
If I did, maybe more text in the changelog entry (or the comment) would help.Ok, so the old code did:
if (((p->flags & PF_MEMALLOC) || ...) && !in_interrupt) { .... goto nopage; }which avoid anything that has
PF_MEMALLOCset from entering into direct reclaim, right?Now, the new code reads:
if (alloc_flags & ALLOC_NO_WATERMARK) { }Which might be false, even though we have
PF_MEMALLOCset -__GFP_NOMEMALLOCcomes to mind.So we have to stop that recursion from happening.
Quoted 10 lines
so we add:
if (
p->flags&PF_MEMALLOC)goto nopage;Now, if it were done before the !wait check, we'd have to consider atomic contexts, but as those are - as you rightly pointed out - handled by the !wait case, we can plainly do this check.
Oh yes, obvious when you explain it, thanks.
cat << END >> Changelog
As the test
- if (((p->flags & PF_MEMALLOC) || unlikely(test_thread_flag(TIF_MEMDIE)))
- && !in_interrupt()) {
- if (!(gfp_mask & __GFP_NOMEMALLOC)) {
has been replaced with a slightly strong
+ if (alloc_flags & ALLOC_NO_WATERMARKS) {
we need to ensure we don't recurse when PF_MEMALLOC is set
END
??
Thanks,
NeilBrown
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/30 mm: tag reseve pages
In reply to Peter ZijlstraTag pages allocated from the reserves with a non-zero page->reserve. This allows us to distinguish and account reserve pages.
--- include/linux/mm_types.h | 1 + mm/page_alloc.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
include/linux/mm_types.h +1 -0
@@ -70,6 +70,7 @@ struct page {union {pgoff_t index;/* Our offset within mapping. */ void *freelist;/* SLUB: freelist req. slab lock */ +int reserve;/* page_alloc: page is a reserve page */ };struct list_head lru;/* Pageout list, eg. active_list * protected by zone->lru_lock !
mm/page_alloc.c +3 -1
@@ -1433,8 +1433,10 @@ zonelist_scan: } page =buffered_rmqueue (preferred_zone, zone, order, gfp_mask); -if (page) +if (page) { + page->reserve = !!(alloc_flags &ALLOC_NO_WATERMARKS );break ; + } this_zone_full:if (NUMA_BUILD )zlc_mark_zone_full (zonelist, z);
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/30 mm: slub: trivial cleanups
In reply to Peter ZijlstraSome cleanups....
--- include/linux/slub_def.h | 7 ++++++- mm/slub.c | 40 ++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 23 deletions(-)
mm/slub.c +18 -22
@@ -27,7 +27,7 @@/* * Lock order: * 1. slab_lock(page) -* 2. slab->list_lock +* 2. node->list_lock * * The slab_lock protects operations on the object of a particular * slab and its metadata in the page struct. If the slab lock
@@ -163,11 +163,11 @@ static struct notifier_block slab_notifi#endif static enum { -DOWN ,/* No slab functionality available */ +DOWN =0 ,/* No slab functionality available */ PARTIAL ,/* kmem_cache_open() works but kmalloc does not */ UP ,/* Everything works but does not show up in sysfs */ SYSFS /* Sysfs up */ -} slab_state =DOWN ; +} slab_state;/* A list of all slab caches on the system */ static DECLARE_RWSEM (slub_lock);
@@ -288,21 +288,22 @@ static inline int slab_index(void *p, ststatic inline struct kmem_cache_order_objects oo_make (int order,unsigned long size) { -struct kmem_cache_order_objects x = { - (order <<16 ) + (PAGE_SIZE << order) / size - }; +struct kmem_cache_order_objects x; + + x.order = order; + x.objects = (PAGE_SIZE << order) / size;return x; }static inline int oo_order (struct kmem_cache_order_objects x) { -return x.x >>16 ; +return x.order; }static inline int oo_objects (struct kmem_cache_order_objects x) { -return x.x & ((1 <<16 ) -1 ); +return x.objects; }#ifdef CONFIG_SLUB_DEBUG
@@ -1076,8 +1077,7 @@ static struct page *allocate_slab(struct flags |= s->allocflags; - page =alloc_slab_page (flags | __GFP_NOWARN | __GFP_NORETRY, node, - oo); + page =alloc_slab_page (flags | __GFP_NOWARN | __GFP_NORETRY, node, oo);if (unlikely (!page)) { oo = s->min;/*
@@ -1099,8 +1099,7 @@ static struct page *allocate_slab(structreturn page; } -static void setup_object (struct kmem_cache *s,struct page *page, -void *object) +static void setup_object (struct kmem_cache *s,struct page *page,void *object) {setup_object_debug (s, page, object);if (unlikely (s->ctor))
@@ -1157,8 +1156,7 @@ static void __free_slab(struct kmem_cachvoid *p;slab_pad_check (s, page); -for_each_object (p, s,page_address (page), - page->objects) +for_each_object (p, s,page_address (page), page->objects)check_object (s, page, p,0 );__ClearPageSlubDebug (page); }
@@ -1224,8 +1222,7 @@ static __always_inline int slab_trylock(/* * Management of partially allocated slabs */ -static void add_partial (struct kmem_cache_node *n, -struct page *page,int tail) +static void add_partial (struct kmem_cache_node *n,struct page *page,int tail) {spin_lock (&n->list_lock); n->nr_partial++;
@@ -1251,8 +1248,8 @@ static void remove_partial(struct kmem_c* * Must hold list_lock. */ -static inline int lock_and_freeze_slab (struct kmem_cache_node *n, -struct page *page) +static inline +int lock_and_freeze_slab (struct kmem_cache_node *n,struct page *page) {if (slab_trylock (page)) {list_del (&page->lru);
@@ -1799,11 +1796,11 @@ static int slub_nomerge;* slub_max_order specifies the order where we begin to stop considering the * number of objects in a slab as critical. If we reach slub_max_order then * we try to keep the page order as low as possible. So we accept more waste -* of space in favor of a small page order. +* of space in favour of a small page order. * * Higher order allocations also allow the placement of more objects in a * slab and thereby reduce object handling overhead. If the user has -* requested a higher mininum order then we start with that one instead of +* requested a higher minimum order then we start with that one instead of * the smallest order which will fit the object. */ static inline int slab_order(int size, int min_objects,
@@ -1816,8 +1813,7 @@ static inline int slab_order(int size, iif ((PAGE_SIZE << min_order) / size >65535 )return get_order (size *65535 ) -1 ; -for (order =max (min_order, -fls (min_objects * size -1 ) -PAGE_SHIFT ); +for (order =max (min_order,fls (min_objects * size -1 ) -PAGE_SHIFT ); order <= max_order; order++) {unsigned long slab_size =PAGE_SIZE << order;
include/linux/slub_def.h +6 -1
@@ -60,7 +60,12 @@ struct kmem_cache_node {* given order would contain. */ struct kmem_cache_order_objects { -unsigned long x; +union { +u32 x; +struct { +u16 order, objects; + }; + }; };/*
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 04/30] mm: slub: trivial cleanups
Hi Peter,
Could you perhaps send this patch separately?
Quoted 3 lines · Peter Zijlstra
plain text document attachment (cleanup-slub.patch) Some cleanups....
Christoph?
Quoted 145 lines
Signed-off-by Peter Zijlstra <[email protected]>--- include/linux/slub_def.h | 7 ++++++- mm/slub.c | 40 ++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 23 deletions(-)Index:
linux-2.6/mm/slub.c
===================================================================mm/slub.c +18
-22@@ -27,7 +27,7 @@/* * Lock order: * 1. slab_lock(page) -* 2. slab->list_lock +* 2. node->list_lock * * The slab_lock protects operations on the object of a particular * slab and its metadata in the page struct. If the slab lock @@ -163,11 +163,11 @@ static struct notifier_block slab_notifi#endif static enum { -DOWN ,/* No slab functionality available */ +DOWN =0 ,/* No slab functionality available */ PARTIAL ,/* kmem_cache_open() works but kmalloc does not */ UP ,/* Everything works but does not show up in sysfs */ SYSFS /* Sysfs up */ -} slab_state =DOWN ; +} slab_state;/* A list of all slab caches on the system */ static DECLARE_RWSEM (slub_lock);@@ -288,21 +288,22 @@ static inline int slab_index(void *p, ststatic inline struct kmem_cache_order_objects oo_make (int order,unsigned long size) { -struct kmem_cache_order_objects x = { - (order <<16 ) + (PAGE_SIZE << order) / size - }; +struct kmem_cache_order_objects x; + + x.order = order; + x.objects = (PAGE_SIZE << order) / size;return x; }static inline int oo_order (struct kmem_cache_order_objects x) { -return x.x >>16 ; +return x.order; }static inline int oo_objects (struct kmem_cache_order_objects x) { -return x.x & ((1 <<16 ) -1 ); +return x.objects; }#ifdef CONFIG_SLUB_DEBUG @@ -1076,8 +1077,7 @@ static struct page *allocate_slab(struct flags |= s->allocflags; - page =alloc_slab_page (flags | __GFP_NOWARN | __GFP_NORETRY, node, - oo); + page =alloc_slab_page (flags | __GFP_NOWARN | __GFP_NORETRY, node, oo);if (unlikely (!page)) { oo = s->min;/* @@ -1099,8 +1099,7 @@ static struct page *allocate_slab(structreturn page; } -static void setup_object (struct kmem_cache *s,struct page *page, -void *object) +static void setup_object (struct kmem_cache *s,struct page *page,void *object) {setup_object_debug (s, page, object);if (unlikely (s->ctor))@@ -1157,8 +1156,7 @@ static void __free_slab(struct kmem_cachvoid *p;slab_pad_check (s, page); -for_each_object (p, s,page_address (page), - page->objects) +for_each_object (p, s,page_address (page), page->objects)check_object (s, page, p,0 );__ClearPageSlubDebug (page); }@@ -1224,8 +1222,7 @@ static __always_inline int slab_trylock(/* * Management of partially allocated slabs */ -static void add_partial (struct kmem_cache_node *n, -struct page *page,int tail) +static void add_partial (struct kmem_cache_node *n,struct page *page,int tail) {spin_lock (&n->list_lock); n->nr_partial++;@@ -1251,8 +1248,8 @@ static void remove_partial(struct kmem_c* * Must hold list_lock. */ -static inline int lock_and_freeze_slab (struct kmem_cache_node *n, -struct page *page) +static inline +int lock_and_freeze_slab (struct kmem_cache_node *n,struct page *page) {if (slab_trylock (page)) {list_del (&page->lru);@@ -1799,11 +1796,11 @@ static int slub_nomerge;* slub_max_order specifies the order where we begin to stop considering the * number of objects in a slab as critical. If we reach slub_max_order then * we try to keep the page order as low as possible. So we accept more waste -* of space in favor of a small page order. +* of space in favour of a small page order. * * Higher order allocations also allow the placement of more objects in a * slab and thereby reduce object handling overhead. If the user has -* requested a higher mininum order then we start with that one instead of +* requested a higher minimum order then we start with that one instead of * the smallest order which will fit the object. */ static inline int slab_order(int size, int min_objects,@@ -1816,8 +1813,7 @@ static inline int slab_order(int size, iif ((PAGE_SIZE << min_order) / size >65535 )return get_order (size *65535 ) -1 ; -for (order =max (min_order, -fls (min_objects * size -1 ) -PAGE_SHIFT ); +for (order =max (min_order,fls (min_objects * size -1 ) -PAGE_SHIFT ); order <= max_order; order++) {unsigned long slab_size =PAGE_SIZE << order;Index:
linux-2.6/include/linux/slub_def.h
===================================================================include/linux/slub_def.h +0
-0@@ -60,7 +60,12 @@ struct kmem_cache_node {* given order would contain. */ struct kmem_cache_order_objects {
include/linux/slub_def.h struct kmem_cache_node { · line 71
Quoted 10 lines
include/linux/slub_def.h +6
-1-unsigned long x; +union { +u32 x; +struct { +u16 order, objects; + }; + }; };/*
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 04/30] mm: slub: trivial cleanups
Quoted 3 lines · Pekka Enberg
Hi Peter,
Could you perhaps send this patch separately?
I think this version applies to mainline without modifications, so you could just take it as is, but sure I can resend..
Quoted 162 lines · Peter Zijlstra
Quoted 3 lines
plain text document attachment (cleanup-slub.patch) Some cleanups....
Reviewed-by Pekka Enberg <[email protected]>Christoph?
Quoted 153 lines
Signed-off-by Peter Zijlstra <[email protected]>--- include/linux/slub_def.h | 7 ++++++- mm/slub.c | 40 ++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 23 deletions(-)Index:
linux-2.6/mm/slub.c
===================================================================mm/slub.c +18
-22@@ -27,7 +27,7 @@/* * Lock order: * 1. slab_lock(page) -* 2. slab->list_lock +* 2. node->list_lock * * The slab_lock protects operations on the object of a particular * slab and its metadata in the page struct. If the slab lock @@ -163,11 +163,11 @@ static struct notifier_block slab_notifi#endif static enum { -DOWN ,/* No slab functionality available */ +DOWN =0 ,/* No slab functionality available */ PARTIAL ,/* kmem_cache_open() works but kmalloc does not */ UP ,/* Everything works but does not show up in sysfs */ SYSFS /* Sysfs up */ -} slab_state =DOWN ; +} slab_state;/* A list of all slab caches on the system */ static DECLARE_RWSEM (slub_lock);@@ -288,21 +288,22 @@ static inline int slab_index(void *p, ststatic inline struct kmem_cache_order_objects oo_make (int order,unsigned long size) { -struct kmem_cache_order_objects x = { - (order <<16 ) + (PAGE_SIZE << order) / size - }; +struct kmem_cache_order_objects x; + + x.order = order; + x.objects = (PAGE_SIZE << order) / size;return x; }static inline int oo_order (struct kmem_cache_order_objects x) { -return x.x >>16 ; +return x.order; }static inline int oo_objects (struct kmem_cache_order_objects x) { -return x.x & ((1 <<16 ) -1 ); +return x.objects; }#ifdef CONFIG_SLUB_DEBUG @@ -1076,8 +1077,7 @@ static struct page *allocate_slab(struct flags |= s->allocflags; - page =alloc_slab_page (flags | __GFP_NOWARN | __GFP_NORETRY, node, - oo); + page =alloc_slab_page (flags | __GFP_NOWARN | __GFP_NORETRY, node, oo);if (unlikely (!page)) { oo = s->min;/* @@ -1099,8 +1099,7 @@ static struct page *allocate_slab(structreturn page; } -static void setup_object (struct kmem_cache *s,struct page *page, -void *object) +static void setup_object (struct kmem_cache *s,struct page *page,void *object) {setup_object_debug (s, page, object);if (unlikely (s->ctor))@@ -1157,8 +1156,7 @@ static void __free_slab(struct kmem_cachvoid *p;slab_pad_check (s, page); -for_each_object (p, s,page_address (page), - page->objects) +for_each_object (p, s,page_address (page), page->objects)check_object (s, page, p,0 );__ClearPageSlubDebug (page); }@@ -1224,8 +1222,7 @@ static __always_inline int slab_trylock(/* * Management of partially allocated slabs */ -static void add_partial (struct kmem_cache_node *n, -struct page *page,int tail) +static void add_partial (struct kmem_cache_node *n,struct page *page,int tail) {spin_lock (&n->list_lock); n->nr_partial++;@@ -1251,8 +1248,8 @@ static void remove_partial(struct kmem_c* * Must hold list_lock. */ -static inline int lock_and_freeze_slab (struct kmem_cache_node *n, -struct page *page) +static inline +int lock_and_freeze_slab (struct kmem_cache_node *n,struct page *page) {if (slab_trylock (page)) {list_del (&page->lru);@@ -1799,11 +1796,11 @@ static int slub_nomerge;* slub_max_order specifies the order where we begin to stop considering the * number of objects in a slab as critical. If we reach slub_max_order then * we try to keep the page order as low as possible. So we accept more waste -* of space in favor of a small page order. +* of space in favour of a small page order. * * Higher order allocations also allow the placement of more objects in a * slab and thereby reduce object handling overhead. If the user has -* requested a higher mininum order then we start with that one instead of +* requested a higher minimum order then we start with that one instead of * the smallest order which will fit the object. */ static inline int slab_order(int size, int min_objects,@@ -1816,8 +1813,7 @@ static inline int slab_order(int size, iif ((PAGE_SIZE << min_order) / size >65535 )return get_order (size *65535 ) -1 ; -for (order =max (min_order, -fls (min_objects * size -1 ) -PAGE_SHIFT ); +for (order =max (min_order,fls (min_objects * size -1 ) -PAGE_SHIFT ); order <= max_order; order++) {unsigned long slab_size =PAGE_SIZE << order;Index:
linux-2.6/include/linux/slub_def.h
===================================================================include/linux/slub_def.h +6
-1@@ -60,7 +60,12 @@ struct kmem_cache_node {* given order would contain. */ struct kmem_cache_order_objects { -unsigned long x; +union { +u32 x; +struct { +u16 order, objects; + }; + }; };
Quoted 3 lines
include/linux/slub_def.h struct kmem_cache_node { · line 71
Quoted 2 lines
include/linux/slub_def.h +0
-0/*
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 04/30] mm: slub: trivial cleanups
Quoted 1 line · Peter Zijlstra
Quoted 1 line
Christoph?
Sorry for the delay but this moving stuff is unending....
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Index:
linux-2.6/mm/slub.c
===================================================================mm/slub.c +0
-0@@ -27,7 +27,7 @@
Quoted 8 lines
Quoted 8 lines
mm/slub.c line 33
Quoted 8 lines
mm/slub.c +1
-1/* * Lock order: * 1. slab_lock(page) -* 2. slab->list_lock +* 2. node->list_lock * * The slab_lock protects operations on the object of a particular * slab and its metadata in the page struct. If the slab lock
Hmmm..... node? Maybe use the struct name? kmem_cache_node?
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
mm/slub.c +2
-2@@ -163,11 +163,11 @@ static struct notifier_block slab_notifi#endif static enum { -DOWN ,/* No slab functionality available */ +DOWN =0 ,/* No slab functionality available */ PARTIAL ,/* kmem_cache_open() works but kmalloc does not */ UP ,/* Everything works but does not show up in sysfs */ SYSFS /* Sysfs up */ -} slab_state =DOWN ; +} slab_state;
Quoted 2 lines
Quoted 2 lines
mm/slub.c static struct notifier_block slab_notifi · line 173
Quoted 2 lines
mm/slub.c +0
-0/* A list of all slab caches on the system */ static DECLARE_RWSEM (slub_lock);
It defaults to the first enum value. We also do not initialize statics with zero.
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
mm/slub.c +4
-3@@ -288,21 +288,22 @@ static inline int slab_index(void *p, ststatic inline struct kmem_cache_order_objects oo_make (int order,unsigned long size) { -struct kmem_cache_order_objects x = { - (order <<16 ) + (PAGE_SIZE << order) / size - }; +struct kmem_cache_order_objects x; + + x.order = order; + x.objects = (PAGE_SIZE << order) / size;
Quoted 3 lines
Quoted 3 lines
mm/slub.c static inline int slab_index(void *p, st · line 298
Quoted 3 lines
mm/slub.c +0
-0return x; }
Another width limitation that will limit the number of objects in a slab to 64k.
Also gcc does not get the fields, wont be able to optimize this as well and it will emit conversion from 16 bit loads.
Quoted 10 lines
Quoted 10 lines
mm/slub.c static struct page *allocate_slab(struct · line 1083
Quoted 10 lines
mm/slub.c +1
-2@@ -1076,8 +1077,7 @@ static struct page *allocate_slab(struct flags |= s->allocflags; - page =alloc_slab_page (flags | __GFP_NOWARN | __GFP_NORETRY, node, - oo); + page =alloc_slab_page (flags | __GFP_NOWARN | __GFP_NORETRY, node, oo);if (unlikely (!page)) { oo = s->min;/*
ok.
Quoted 10 lines
Quoted 10 lines
mm/slub.c static struct page *allocate_slab(struct · line 1105
Quoted 10 lines
mm/slub.c +1
-2@@ -1099,8 +1099,7 @@ static struct page *allocate_slab(structreturn page; } -static void setup_object (struct kmem_cache *s,struct page *page, -void *object) +static void setup_object (struct kmem_cache *s,struct page *page,void *object) {setup_object_debug (s, page, object);if (unlikely (s->ctor))
Hmmm. You are moving it back on one line and Andrew will cut it up again later? This seems to be oscillating...
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
mm/slub.c +1
-1@@ -1799,11 +1796,11 @@ static int slub_nomerge;* slub_max_order specifies the order where we begin to stop considering the * number of objects in a slab as critical. If we reach slub_max_order then * we try to keep the page order as low as possible. So we accept more waste -* of space in favor of a small page order. +* of space in favour of a small page order.
Quoted 8 lines
Quoted 8 lines
mm/slub.c static int slub_nomerge; · line 1806
Quoted 8 lines
mm/slub.c +1
-1* * Higher order allocations also allow the placement of more objects in a * slab and thereby reduce object handling overhead. If the user has -* requested a higher mininum order then we start with that one instead of +* requested a higher minimum order then we start with that one instead of * the smallest order which will fit the object. */ static inline int slab_order(int size, int min_objects,
Ack.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 04/30] mm: slub: trivial cleanups
Quoted 35 lines · Christoph Lameter
Quoted 1 line · Peter Zijlstra
Quoted 1 line
Christoph?
Sorry for the delay but this moving stuff is unending....
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Index:
linux-2.6/mm/slub.c
===================================================================mm/slub.c +0
-0@@ -27,7 +27,7 @@Quoted 8 lines
Quoted 8 lines
mm/slub.c line 33
Quoted 8 lines
mm/slub.c +1
-1/* * Lock order: * 1. slab_lock(page) -* 2. slab->list_lock +* 2. node->list_lock * * The slab_lock protects operations on the object of a particular * slab and its metadata in the page struct. If the slab lock Hmmm..... node? Maybe use the struct name?
kmem_cache_node?Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
mm/slub.c +2
-2@@ -163,11 +163,11 @@ static struct notifier_block slab_notifi#endif static enum { -DOWN ,/* No slab functionality available */ +DOWN =0 ,/* No slab functionality available */ PARTIAL ,/* kmem_cache_open() works but kmalloc does not */ UP ,/* Everything works but does not show up in sysfs */ SYSFS /* Sysfs up */ -} slab_state =DOWN ; +} slab_state;
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
mm/slub.c static struct notifier_block slab_notifi · line 173
Quoted 2 lines
mm/slub.c +0
-0/* A list of all slab caches on the system */ static DECLARE_RWSEM (slub_lock);It defaults to the first enum value. We also do not initialize statics with zero.
I seem to recall differently, I thought we explicitly init global stuff to 0.
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
mm/slub.c +4
-3@@ -288,21 +288,22 @@ static inline int slab_index(void *p, ststatic inline struct kmem_cache_order_objects oo_make (int order,unsigned long size) { -struct kmem_cache_order_objects x = { - (order <<16 ) + (PAGE_SIZE << order) / size - }; +struct kmem_cache_order_objects x; + + x.order = order; + x.objects = (PAGE_SIZE << order) / size;
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
mm/slub.c static inline int slab_index(void *p, st · line 298
Quoted 3 lines
mm/slub.c +0
-0return x; }Another width limitation that will limit the number of objects in a slab to 64k.
Also gcc does not get the fields, wont be able to optimize this as well and it will emit conversion from 16 bit loads.
Well, it was already 16 by virtue of the old code.
GCC emmiting rubbish code due to the union would be sad - I can respin without this.
Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
mm/slub.c static struct page *allocate_slab(struct · line 1083
Quoted 10 lines
mm/slub.c +1
-2@@ -1076,8 +1077,7 @@ static struct page *allocate_slab(struct flags |= s->allocflags; - page =alloc_slab_page (flags | __GFP_NOWARN | __GFP_NORETRY, node, - oo); + page =alloc_slab_page (flags | __GFP_NOWARN | __GFP_NORETRY, node, oo);if (unlikely (!page)) { oo = s->min;/* ok.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
mm/slub.c +0
-0@@ -1099,8 +1099,7 @@ static struct page *allocate_slab(structreturn page; }
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
mm/slub.c static struct page *allocate_slab(struct · line 1105
Quoted 6 lines
mm/slub.c +1
-2-static void setup_object (struct kmem_cache *s,struct page *page, -void *object) +static void setup_object (struct kmem_cache *s,struct page *page,void *object) {setup_object_debug (s, page, object);if (unlikely (s->ctor))Hmmm. You are moving it back on one line and Andrew will cut it up again later? This seems to be oscillating...
Gah, somehow I got convinced the result was <= 80..
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
mm/slub.c +1
-1@@ -1799,11 +1796,11 @@ static int slub_nomerge;* slub_max_order specifies the order where we begin to stop considering the * number of objects in a slab as critical. If we reach slub_max_order then * we try to keep the page order as low as possible. So we accept more waste -* of space in favor of a small page order. +* of space in favour of a small page order. * * Higher order allocations also allow the placement of more objects in a
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
mm/slub.c static int slub_nomerge; · line 1806
Quoted 6 lines
mm/slub.c +1
-1* slab and thereby reduce object handling overhead. If the user has -* requested a higher mininum order then we start with that one instead of +* requested a higher minimum order then we start with that one instead of * the smallest order which will fit the object. */ static inline int slab_order(int size, int min_objects,Ack.
OK, will send a new one without the bad bits..
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Pekka Enberg
AppliedRe: [PATCH 04/30] mm: slub: trivial cleanups
In reply to Peter ZijlstraQuoted 3 lines · Peter Zijlstra
Some cleanups....
Signed-off-by Peter Zijlstra <[email protected]>
Applied, thanks!
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 5/30 mm: slb: add knowledge of reserve pages
In reply to Peter ZijlstraRestrict objects from reserve slabs (ALLOC_NO_WATERMARKS) to allocation contexts that are entitled to it. This is done to ensure reserve pages don't leak out and get consumed.
--- include/linux/slub_def.h | 1 mm/slab.c | 60 +++++++++++++++++++++++++++++++++++++++-------- mm/slub.c | 28 ++++++++++++++++++--- 3 files changed, 75 insertions(+), 14 deletions(-)
mm/slub.c +23 -5
@@ -23,6 +23,7 @@#include <linux/kallsyms.h> #include <linux/memory.h> #include <linux/math64.h> +#include "internal.h" /* * Lock order:
@@ -1106,7 +1107,8 @@ static void setup_object(struct kmem_cac s->ctor (s, object); } -static struct page *new_slab (struct kmem_cache *s,gfp_t flags,int node) +static +struct page *new_slab (struct kmem_cache *s,gfp_t flags,int node,int *reserve) {struct page *page;void *start;
@@ -1120,6 +1122,8 @@ static struct page *new_slab(struct kmemif (!page) goto out; + *reserve = page->reserve; +inc_slabs_node (s,page_to_nid (page), page->objects); page->slab = s; page->flags |=1 << PG_slab;
@@ -1509,10 +1513,20 @@ static void *__slab_alloc(struct kmem_ca {void **object;struct page *new; +int reserve;/* We handle __GFP_ZERO in the caller */ gfpflags &= ~__GFP_ZERO; +if (unlikely (c->reserve)) { +/* +* If the current slab is a reserve slab and the current +* allocation context does not allow access to the reserves we +* must force an allocation to test the current levels. +*/ +if (!(gfp_to_alloc_flags (gfpflags) &ALLOC_NO_WATERMARKS )) + goto grow_slab; + }if (!c->page) goto new_slab;
@@ -1526,7 +1540,7 @@ load_freelist: object = c->page->freelist;if (unlikely (!object)) goto another_slab; -if (unlikely (SLABDEBUG &&PageSlubDebug (c->page))) +if (unlikely (PageSlubDebug (c->page) || c->reserve)) goto debug; c->freelist = object[c->offset];
@@ -1549,16 +1563,18 @@ new_slab: goto load_freelist; } +grow_slab:if (gfpflags & __GFP_WAIT)local_irq_enable (); - new =new_slab (s, gfpflags, node); + new =new_slab (s, gfpflags, node, &reserve);if (gfpflags & __GFP_WAIT)local_irq_disable ();if (new) { c =get_cpu_slab (s,smp_processor_id ()); + c->reserve = reserve;stat (c,ALLOC_SLAB );if (c->page)flush_slab (s, c);
@@ -1569,7 +1585,8 @@ new_slab: }return NULL ; debug: -if (!alloc_debug_processing (s, c->page, object, addr)) +if (PageSlubDebug (c->page) && + !alloc_debug_processing (s, c->page, object, addr)) goto another_slab; c->page->inuse++;
@@ -2068,10 +2085,11 @@ static struct kmem_cache_node *early_kmestruct page *page;struct kmem_cache_node *n;unsigned long flags; +int reserve;BUG_ON (kmalloc_caches->size <sizeof (struct kmem_cache_node )); - page =new_slab (kmalloc_caches, gfpflags, node); + page =new_slab (kmalloc_caches, gfpflags, node, &reserve);BUG_ON (!page);if (page_to_nid (page) != node) {
include/linux/slub_def.h +1 -0
@@ -38,6 +38,7 @@ struct kmem_cache_cpu {int node;/* The node of the page (or -1 for debug) */ unsigned int offset;/* Freepointer offset (in word units) */ unsigned int objsize;/* Size of an object (from kmem_cache) */ +int reserve;/* Did the current page come from the reserve */ #ifdef CONFIG_SLUB_STATS unsigned stat[NR_SLUB_STAT_ITEMS ];#endif
mm/slab.c +51 -9
184 lines not on this page · raw message
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 05/30] mm: slb: add knowledge of reserve pages
Quoted 3 lines · On Thursday July 24, [email protected] wrote:
Restrict objects from reserve slabs (
ALLOC_NO_WATERMARKS) to allocation contexts that are entitled to it. This is done to ensure reserve pages don't leak out and get consumed.
This looks good (we are still missing slob though, aren't we :-( )
mm/slub.c load_freelist: · line 1544
Quoted 7 lines
mm/slub.c +1
-1@@ -1526,7 +1540,7 @@ load_freelist: object = c->page->freelist;if (unlikely (!object)) goto another_slab; -if (unlikely (SLABDEBUG &&PageSlubDebug (c->page))) +if (unlikely (PageSlubDebug (c->page) || c->reserve)) goto debug;
This looks suspiciously like debugging code that you have left in. Is it??
mm/slab.c struct array_cache { · line 271
Quoted 7 lines
mm/slab.c +2
-1@@ -265,7 +267,8 @@ struct array_cache {unsigned int avail;unsigned int limit;unsigned int batchcount; -unsigned int touched; + unsigned int touched:1, + reserve:1;
This sort of thing always worries me.
It is a per-cpu data structure so you won't get SMP races corrupting fields. But you do get read-modify-write in place of simple updates. I guess it's not a problem.. But it worries me :-)
NeilBrown
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 05/30] mm: slb: add knowledge of reserve pages
Quoted 6 lines · Neil Brown
Quoted 3 lines · On Thursday July 24, [email protected] wrote:
Restrict objects from reserve slabs (
ALLOC_NO_WATERMARKS) to allocation contexts that are entitled to it. This is done to ensure reserve pages don't leak out and get consumed.This looks good (we are still missing slob though, aren't we :-( )
I actually have that now, just needs some testing..
Quoted 10 lines
mm/slub.c load_freelist: · line 1544
Quoted 7 lines
mm/slub.c +1
-1@@ -1526,7 +1540,7 @@ load_freelist: object = c->page->freelist;if (unlikely (!object)) goto another_slab; -if (unlikely (SLABDEBUG &&PageSlubDebug (c->page))) +if (unlikely (PageSlubDebug (c->page) || c->reserve)) goto debug;This looks suspiciously like debugging code that you have left in. Is it??
Its not, we need to force slub into the debug slow path when we have a reserve page, otherwise we cannot do the permission check on each allocation.
Quoted 4 lines
Quoted 4 lines
mm/slab.c +0
-0@@ -265,7 +267,8 @@ struct array_cache {unsigned int avail;unsigned int limit;unsigned int batchcount;
Quoted 8 lines
mm/slab.c struct array_cache { · line 271
Quoted 3 lines
mm/slab.c +2
-1-unsigned int touched; + unsigned int touched:1, + reserve:1;This sort of thing always worries me.
It is a per-cpu data structure so you won't get SMP races corrupting fields. But you do get read-modify-write in place of simple updates. I guess it's not a problem.. But it worries me :-)
Right,.. do people prefer I just add another int?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 05/30] mm: slb: add knowledge of reserve pages
Quoted 9 lines · On Tuesday August 12, [email protected] wrote:
Quoted 6 lines · Neil Brown
Quoted 3 lines · On Thursday July 24, [email protected] wrote:
Restrict objects from reserve slabs (
ALLOC_NO_WATERMARKS) to allocation contexts that are entitled to it. This is done to ensure reserve pages don't leak out and get consumed.This looks good (we are still missing slob though, aren't we :-( )
I actually have that now, just needs some testing..
Cool!
Quoted 12 lines
Quoted 11 lines
mm/slub.c load_freelist: · line 1544
Quoted 8 lines
mm/slub.c +1
-1@@ -1526,7 +1540,7 @@ load_freelist: object = c->page->freelist;if (unlikely (!object)) goto another_slab; -if (unlikely (SLABDEBUG &&PageSlubDebug (c->page))) +if (unlikely (PageSlubDebug (c->page) || c->reserve)) goto debug;This looks suspiciously like debugging code that you have left in. Is it??
Quoted 3 lines
Its not, we need to force slub into the debug slow path when we have a reserve page, otherwise we cannot do the permission check on each allocation.
I see.... a little. I'm trying to avoid understanding slub too deeply, I don't want to use up valuable brain cell :-) Would we be justified in changing the label from 'debug:' to 'slow_path:' or something? And if it is just c->reserve, should we avoid the call to alloc_debug_processing?
Thanks,
NeilBrown
Quoted 14 lines
Quoted 13 lines
mm/slab.c struct array_cache { · line 271
Quoted 8 lines
mm/slab.c +2
-1@@ -265,7 +267,8 @@ struct array_cache {unsigned int avail;unsigned int limit;unsigned int batchcount; -unsigned int touched; + unsigned int touched:1, + reserve:1;This sort of thing always worries me.
It is a per-cpu data structure so you won't get SMP races corrupting fields. But you do get read-modify-write in place of simple updates. I guess it's not a problem.. But it worries me :-)
Quoted 1 line
Right,.. do people prefer I just add another int?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 05/30] mm: slb: add knowledge of reserve pages
Quoted 25 lines · Neil Brown
Quoted 9 lines · On Tuesday August 12, [email protected] wrote:
Quoted 6 lines · Neil Brown
Quoted 3 lines · On Thursday July 24, [email protected] wrote:
Restrict objects from reserve slabs (
ALLOC_NO_WATERMARKS) to allocation contexts that are entitled to it. This is done to ensure reserve pages don't leak out and get consumed.This looks good (we are still missing slob though, aren't we :-( )
I actually have that now, just needs some testing..
Cool!
Quoted 12 lines
Quoted 11 lines
Review load_freelist: · line 1544
Quoted 8 lines
(quoted diff) +1
-1@@ -1526,7 +1540,7 @@ load_freelist: object = c->page->freelist; if (unlikely(!object)) goto another_slab; - if (unlikely(SLABDEBUG && PageSlubDebug(c->page))) + if (unlikely(PageSlubDebug(c->page) || c->reserve)) goto debug;This looks suspiciously like debugging code that you have left in. Is it??
Quoted 6 lines
Quoted 3 lines
Its not, we need to force slub into the debug slow path when we have a reserve page, otherwise we cannot do the permission check on each allocation.
I see.... a little. I'm trying to avoid understanding slub too deeply, I don't want to use up valuable brain cell :-)
:-)
Quoted 2 lines
Would we be justified in changing the label from 'debug:' to '
slow_path:' or something?
Could do I guess.
mm/slub.c +12 -2
@@ -1543,7 +1543,7 @@ load_freelist:if (unlikely (!object)) goto another_slab;if (unlikely (PageSlubDebug (c->page) || c->reserve)) - goto debug; + goto slow_path; c->freelist = object[c->offset]; c->page->inuse = c->page->objects;
@@ -1586,11 +1586,21 @@ grow_slab: goto load_freelist; }return NULL ; -debug: + +slow_path:if (PageSlubDebug (c->page) && !alloc_debug_processing (s, c->page, object, addr)) goto another_slab; +/* +* Avoid the slub fast path in slab_alloc by not setting +* c->freelist and the fast path in slab_fere by making +* node_match() fail by setting c->node to -1. +* +* We use this for for debug checks and reserve handling, +* which needs to do permission checks on each allocation. +*/ + c->page->inuse++; c->page->freelist = object[c->offset]; c->node =-1 ;
Quoted 2 lines
And if it is just
c->reserve, should
we avoid the call toalloc_debug_processing?
We already do:
if (PageSlubDebug(c->page) && !alloc_debug_processing(s, c->page, object, addr)) goto another_slab;
since in that case PageSlubDebug() will be false.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 6/30 mm: kmem_alloc_estimate()
In reply to Peter ZijlstraProvide a method to get the upper bound on the pages needed to allocate a given number of objects from a given kmem_cache.
This lays the foundation for a generic reserve framework as presented in a later patch in this series. This framework needs to convert object demand (kmalloc() bytes, kmem_cache_alloc() objects) to pages.
--- include/linux/slab.h | 4 ++ mm/slab.c | 75 +++++++++++++++++++++++++++++++++++++++++++ mm/slub.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+)
include/linux/slab.h +4 -0
@@ -65,6 +65,8 @@ void kmem_cache_free(struct kmem_cache *unsigned int kmem_cache_size (struct kmem_cache *);const char *kmem_cache_name (struct kmem_cache *);int kmem_ptr_validate (struct kmem_cache *cachep,const void *ptr); +unsigned kmem_alloc_estimate (struct kmem_cache *cachep, +gfp_t flags,int objects);/* * Please use this macro to create slab caches. Simply specify the
@@ -99,6 +101,8 @@ int kmem_ptr_validate(struct kmem_cachevoid *__must_check krealloc (const void *,size_t ,gfp_t );void kfree (const void *);size_t ksize (const void *); +unsigned kmalloc_estimate_fixed (size_t ,gfp_t ,int ); +unsigned kmalloc_estimate_variable (gfp_t ,size_t );/* * Allocator specific definitions. These are mainly used to establish optimized
mm/slub.c +87 -0
99 lines not on this page · raw message
mm/slab.c +75 -0
81 lines not on this page · raw message
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 06/30] mm: kmem_alloc_estimate()
Hi Peter,
Quoted 29 lines · Peter Zijlstra
plain text document attachment (mm-kmem_estimate_pages.patch) Provide a method to get the upper bound on the pages needed to allocate a given number of objects from a given
kmem_cache.This lays the foundation for a generic reserve framework as presented in a later patch in this series. This framework needs to convert object demand (
kmalloc()bytes,kmem_cache_alloc()objects) to pages.Signed-off-by Peter Zijlstra <[email protected]>--- include/linux/slab.h | 4 ++ mm/slab.c | 75 +++++++++++++++++++++++++++++++++++++++++++ mm/slub.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+)Index:
linux-2.6/include/linux/slab.h
===================================================================include/linux/slab.h +2
-0@@ -65,6 +65,8 @@ void kmem_cache_free(struct kmem_cache *unsigned int kmem_cache_size (struct kmem_cache *);const char *kmem_cache_name (struct kmem_cache *);int kmem_ptr_validate (struct kmem_cache *cachep,const void *ptr); +unsigned kmem_alloc_estimate (struct kmem_cache *cachep, +gfp_t flags,int objects);/* * Please use this macro to create slab caches. Simply specify the
include/linux/slab.h int kmem_ptr_validate(struct kmem_cache · line 103
Quoted 3 lines
include/linux/slab.h +0
-0@@ -99,6 +101,8 @@ int kmem_ptr_validate(struct kmem_cachevoid *__must_check krealloc (const void *,size_t ,gfp_t );void kfree (const void *);size_t ksize (const void *);
Just a nitpick, but:
include/linux/slab.h int kmem_ptr_validate(struct kmem_cache · line 104
Quoted 1 line
include/linux/slab.h +1
-0+unsigned kmalloc_estimate_fixed (size_t ,gfp_t ,int );
kmalloc_estimate_objs()?
include/linux/slab.h int kmem_ptr_validate(struct kmem_cache · line 105
Quoted 1 line
include/linux/slab.h +1
-0+unsigned kmalloc_estimate_variable (gfp_t ,size_t );
kmalloc_estimate_bytes()?
Quoted 24 lines
include/linux/slab.h +0
-0/* * Allocator specific definitions. These are mainly used to establish optimized Index:
linux-2.6/mm/slub.c
===================================================================mm/slub.c +13
-0@@ -2412,6 +2412,42 @@ const char *kmem_cache_name(struct kmem_ }EXPORT_SYMBOL (kmem_cache_name); +/* +* Calculate the upper bound of pages required to sequentially allocate +* @objects objects from @cachep. +* +* We should use s->min_objects because those are the least efficient. +*/ +unsigned kmem_alloc_estimate (struct kmem_cache *s,gfp_t flags,int objects) +{ +unsigned long pages; +struct kmem_cache_order_objects x; + +if (WARN_ON (!s) ||WARN_ON (!oo_objects (s->min))) +return 0 ;
mm/slub.c const char *kmem_cache_name(struct kmem_ · line 2437
Quoted 10 lines
mm/slub.c +10
-0+ + x = s->min; + pages =DIV_ROUND_UP (objects,oo_objects (x)) <<oo_order (x); + +/* +* Account the possible additional overhead if the slab holds more that +* one object. Use s->max_objects because that's the worst case. +*/ + x = s->oo; +if (oo_objects (x) >1 ) {
Hmm, I'm not sure why slab with just one object is treated separately here. Surely you have per-CPU slabs then as well?
mm/slub.c const char *kmem_cache_name(struct kmem_ · line 2444
Quoted 7 lines
mm/slub.c +7
-0+/* +* Account the possible additional overhead if per cpu slabs +* are currently empty and have to be allocated. This is very +* unlikely but a possible scenario immediately after +* kmem_cache_shrink. +*/ + pages +=num_online_cpus () <<oo_order (x);
Isn't this problematic with CPU hotplug? Shouldn't we use num_possible_cpus() here?
Quoted 31 lines
mm/slub.c +24
-0+ } + +return pages; +} +EXPORT_SYMBOL_GPL (kmem_alloc_estimate); +static void list_slab_objects (struct kmem_cache *s,struct page *page,const char *text) {@@ -2789,6 +2825,57 @@ void kfree(const void *x)EXPORT_SYMBOL (kfree);/* +* Calculate the upper bound of pages required to sequentially allocate +* @count objects of @size bytes from kmalloc given @flags. +*/ +unsigned kmalloc_estimate_fixed (size_t size,gfp_t flags,int count) +{ +struct kmem_cache *s =get_slab (size, flags); +if (!s) +return 0 ; + +return kmem_alloc_estimate (s, flags, count); + +} +EXPORT_SYMBOL_GPL (kmalloc_estimate_fixed); + +/* +* Calculate the upper bound of pages requires to sequentially allocate @bytes +* from kmalloc in an unspecified number of allocations of nonuniform size. +*/
mm/slub.c void kfree(const void *x) · line 2855
Quoted 10 lines
mm/slub.c +10
-0+unsigned kmalloc_estimate_variable (gfp_t flags,size_t bytes) +{ +int i; +unsigned long pages; + +/* +* multiply by two, in order to account the worst case slack space +* due to the power-of-two allocation sizes. +*/ + pages =DIV_ROUND_UP (2 * bytes,PAGE_SIZE );
For bytes > PAGE_SIZE this doesn't look right (for SLUB). We do page allocator pass-through which means that we'll be grabbing high order pages which can be bigger than what 'pages' is here.
Quoted 42 lines
mm/slub.c +23
-0+ +/* +* add the kmem_cache overhead of each possible kmalloc cache +*/ +for (i =1 ; i <PAGE_SHIFT ; i++) { +struct kmem_cache *s; + +#ifdef CONFIG_ZONE_DMA +if (unlikely (flags &SLUB_DMA )) + s =dma_kmalloc_cache (i, flags); + else +#endif + s = &kmalloc_caches[i]; + +if (s) + pages +=kmem_alloc_estimate (s, flags,0 ); + } + +return pages; +} +EXPORT_SYMBOL_GPL (kmalloc_estimate_variable); + +/* * kmem_cache_shrink removes empty slabs from the partial lists and sorts * the remaining slabs by the number of items in use. The slabs with the * most items in use come first. New allocations will then fill those up Index:
linux-2.6/mm/slab.c
===================================================================mm/slab.c +8
-0@@ -3854,6 +3854,81 @@ const char *kmem_cache_name(struct kmem_EXPORT_SYMBOL_GPL (kmem_cache_name);/* +* Calculate the upper bound of pages required to sequentially allocate +* @objects objects from @cachep. +*/ +unsigned kmem_alloc_estimate (struct kmem_cache *cachep, +gfp_t flags,int objects) +{ +/* +* (1) memory for objects,
mm/slab.c const char *kmem_cache_name(struct kmem_ · line 3874
Quoted 10 lines
mm/slab.c +10
-0+*/ +unsigned nr_slabs =DIV_ROUND_UP (objects, cachep->num); +unsigned nr_pages = nr_slabs << cachep->gfporder; + +/* +* (2) memory for each per-cpu queue (nr_cpu_ids), +* (3) memory for each per-node alien queues (nr_cpu_ids), and +* (4) some amount of memory for the slab management structures +* +* XXX: truely account these
Heh, yes please. Or add a comment why it doesn't matter.
Quoted 61 lines
mm/slab.c +57
-0+*/ + nr_pages +=1 +ilog2 (nr_pages); + +return nr_pages; +} + +/* +* Calculate the upper bound of pages required to sequentially allocate +* @count objects of @size bytes from kmalloc given @flags. +*/ +unsigned kmalloc_estimate_fixed (size_t size,gfp_t flags,int count) +{ +struct kmem_cache *s =kmem_find_general_cachep (size, flags); +if (!s) +return 0 ; + +return kmem_alloc_estimate (s, flags, count); +} +EXPORT_SYMBOL_GPL (kmalloc_estimate_fixed); + +/* +* Calculate the upper bound of pages requires to sequentially allocate @bytes +* from kmalloc in an unspecified number of allocations of nonuniform size. +*/ +unsigned kmalloc_estimate_variable (gfp_t flags,size_t bytes) +{ +unsigned long pages; +struct cache_sizes *csizep = malloc_sizes; + +/* +* multiply by two, in order to account the worst case slack space +* due to the power-of-two allocation sizes. +*/ + pages =DIV_ROUND_UP (2 * bytes,PAGE_SIZE ); + +/* +* add the kmem_cache overhead of each possible kmalloc cache +*/ +for (csizep = malloc_sizes; csizep->cs_cachep; csizep++) { +struct kmem_cache *s; + +#ifdef CONFIG_ZONE_DMA +if (unlikely (flags & __GFP_DMA)) + s = csizep->cs_dmacachep; + else +#endif + s = csizep->cs_cachep; + +if (s) + pages +=kmem_alloc_estimate (s, flags,0 ); + } + +return pages; +} +EXPORT_SYMBOL_GPL (kmalloc_estimate_variable); + +/* * This initializes kmem_list3 or resizes various caches for all nodes. */ static int alloc_kmemlist (struct kmem_cache *cachep)
Re: [PATCH 06/30] mm: kmem_alloc_estimate()
Quoted 6 lines · Pekka Enberg
Hi Peter,
On Thu, 2008-07-24 at 16:00 +0200, Peter Zijlstra wrote:
Just a nitpick, but:
Quoted 7 lines
Quoted 1 line
+unsigned
kmalloc_estimate_fixed(size_t, gfp_t, int);
kmalloc_estimate_objs()?Quoted 1 line
+unsigned
kmalloc_estimate_variable(gfp_t, size_t);
kmalloc_estimate_bytes()?
Sounds good, I'll do some sed magic on the patch-set to make it happen.
Quoted 29 lines
Quoted 29 lines
/*
* Allocator specific definitions. These are mainly used to establish optimized
Index:linux-2.6/mm/slub.c
===================================================================mm/slub.c +18
-0@@ -2412,6 +2412,42 @@ const char *kmem_cache_name(struct kmem_ }EXPORT_SYMBOL (kmem_cache_name); +/* +* Calculate the upper bound of pages required to sequentially allocate +* @objects objects from @cachep. +* +* We should use s->min_objects because those are the least efficient. +*/ +unsigned kmem_alloc_estimate (struct kmem_cache *s,gfp_t flags,int objects) +{ +unsigned long pages; +struct kmem_cache_order_objects x; + +if (WARN_ON (!s) ||WARN_ON (!oo_objects (s->min))) +return 0 ; + + x = s->min; + pages =DIV_ROUND_UP (objects,oo_objects (x)) <<oo_order (x); + +/*
Quoted 8 lines
mm/slub.c const char *kmem_cache_name(struct kmem_ · line 2437
Quoted 5 lines
mm/slub.c +5
-0+* Account the possible additional overhead if the slab holds more that +* one object. Use s->max_objects because that's the worst case. +*/ + x = s->oo; +if (oo_objects (x) >1 ) {Hmm, I'm not sure why slab with just one object is treated separately here. Surely you have per-CPU slabs then as well?
The thought was that if the slab only contains 1 obj, then the per-cpu slabs are always full (or empty but already there), so you don't loose memory to other cpu's having half-filled slabs.
Say you want to reserve memory for 10 object.
In the 1 object per slab case, you will always allocate a slab, no matter what cpu you do the allocation on.
With say, 16 objects per slab and allocations spread across 2 cpus, you have to allow for per-cpu slabs to be half-filled.
Quoted 10 lines
mm/slub.c const char *kmem_cache_name(struct kmem_ · line 2444
Quoted 7 lines
mm/slub.c +7
-0+/* +* Account the possible additional overhead if per cpu slabs +* are currently empty and have to be allocated. This is very +* unlikely but a possible scenario immediately after +* kmem_cache_shrink. +*/ + pages +=num_online_cpus () <<oo_order (x);Isn't this problematic with CPU hotplug? Shouldn't we use
num_possible_cpus()here?
ACK, thanks!
Quoted 10 lines
Quoted 10 lines
mm/slub.c +10
-0+/* +* Calculate the upper bound of pages requires to sequentially allocate @bytes +* from kmalloc in an unspecified number of allocations of nonuniform size. +*/ +unsigned kmalloc_estimate_variable (gfp_t flags,size_t bytes) +{ +int i; +unsigned long pages; + +/*
Quoted 8 lines
mm/slub.c void kfree(const void *x) · line 2855
Quoted 4 lines
mm/slub.c +4
-0+* multiply by two, in order to account the worst case slack space +* due to the power-of-two allocation sizes. +*/ + pages =DIV_ROUND_UP (2 * bytes,PAGE_SIZE );For bytes >
PAGE_SIZEthis doesn't look right (for SLUB). We do page allocator pass-through which means that we'll be grabbing high order pages which can be bigger than what 'pages' is here.
Hehe - you actually made me think here.
Satisfying allocations from a bucket distribution with power-of-two (which page alloc order satisfies) has a worst case slack space of:
S(x) = 2^n - (2^(n-1)) - 1, n = ceil(log2(x))
This can be seen for the cases where x = 2^i + 1.
If we approximate S(x) by 2^(n-1) and compute the slack ratio for any given x:
R(x) ~ 2^n / 2^(n-1) = 2
We'll see that for any amount of x, we can only use half that due to slack space.
Therefore, by multiplying the demand @bytes by 2 we'll always have enough to cover the worst case slack considering the power-of-two allocation buckets.
In example, if @bytes asks for 4 pages + 1 byte = 16385 bytes (assuming 4k pages), then the above will request 8 pages + 2 bytes, rounded up to pages, is 9 pages. Which is enough to satisfy the order 3 allocation needed for the 8 contiguous pages to store the requested 16385 bytes.
Quoted 20 lines
Quoted 20 lines
Index:
linux-2.6/mm/slab.c
===================================================================mm/slab.c +12
-0@@ -3854,6 +3854,81 @@ const char *kmem_cache_name(struct kmem_EXPORT_SYMBOL_GPL (kmem_cache_name);/* +* Calculate the upper bound of pages required to sequentially allocate +* @objects objects from @cachep. +*/ +unsigned kmem_alloc_estimate (struct kmem_cache *cachep, +gfp_t flags,int objects) +{ +/* +* (1) memory for objects, +*/ +unsigned nr_slabs =DIV_ROUND_UP (objects, cachep->num); +unsigned nr_pages = nr_slabs << cachep->gfporder; +
Quoted 8 lines
mm/slab.c const char *kmem_cache_name(struct kmem_ · line 3874
Quoted 6 lines
mm/slab.c +6
-0+/* +* (2) memory for each per-cpu queue (nr_cpu_ids), +* (3) memory for each per-node alien queues (nr_cpu_ids), and +* (4) some amount of memory for the slab management structures +* +* XXX: truely account these Heh, yes please. Or add a comment why it doesn't matter.
Since you were the one I cribbed that comment from some (long) time ago, can you advise on how well the below approximation is to an upper bound on the above factors - assuming SLAB will live long enough to make it worth the effort?
Quoted 5 lines
mm/slab.c const char *kmem_cache_name(struct kmem_ · line 3879
Quoted 5 lines
mm/slab.c +5
-0+*/ + nr_pages +=1 +ilog2 (nr_pages); + +return nr_pages; +}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 06/30] mm: kmem_alloc_estimate()
Quoted 18 lines · Peter Zijlstra
Quoted 9 lines
Quoted 9 lines
mm/slub.c +9
-0+/* +* Calculate the upper bound of pages requires to sequentially allocate @bytes +* from kmalloc in an unspecified number of allocations of nonuniform size. +*/ +unsigned kmalloc_estimate_variable (gfp_t flags,size_t bytes) +{ +int i; +unsigned long pages; +Quoted 8 lines
mm/slub.c void kfree(const void *x) · line 2855
Quoted 5 lines
mm/slub.c +5
-0+/* +* multiply by two, in order to account the worst case slack space +* due to the power-of-two allocation sizes. +*/ + pages =DIV_ROUND_UP (2 * bytes,PAGE_SIZE );For bytes >
PAGE_SIZEthis doesn't look right (for SLUB). We do page allocator pass-through which means that we'll be grabbing high order pages which can be bigger than what 'pages' is here.
Quoted 6 lines
Satisfying allocations from a bucket distribution with power-of-two (which page alloc order satisfies) has a worst case slack space of:
S(x) = 2^n - (2^(n-1)) - 1, n = ceil(log2(x))
This can be seen for the cases where x = 2^i + 1.
The needed bytes for a kmalloc allocation with size > PAGE_SIZE is
get_order(size) << PAGE_SHIFT bytes.
See kmalloc_large().
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 7/30 mm: allow PF_MEMALLOC from softirq context
In reply to Peter ZijlstraAllow PF_MEMALLOC to be set in softirq context.
This is needed to allow network softirq packet processing to make use of PF_MEMALLOC.
--- include/linux/sched.h | 7 +++++++ kernel/softirq.c | 3 +++ mm/page_alloc.c | 7 ++++--- 3 files changed, 14 insertions(+), 3 deletions(-)
mm/page_alloc.c +4 -3
@@ -1449,9 +1449,10 @@ int gfp_to_alloc_flags(gfp_t gfp_mask) alloc_flags |=ALLOC_HARDER ;if (likely (!(gfp_mask & __GFP_NOMEMALLOC))) { -if (!in_interrupt () && - ((p->flags &PF_MEMALLOC ) || -unlikely (test_thread_flag (TIF_MEMDIE )))) +if (!in_irq () && (p->flags &PF_MEMALLOC )) + alloc_flags |=ALLOC_NO_WATERMARKS ; +else if (!in_interrupt () && +unlikely (test_thread_flag (TIF_MEMDIE ))) alloc_flags |=ALLOC_NO_WATERMARKS ; }
kernel/softirq.c +3 -0
@@ -213,6 +213,8 @@ asmlinkage void __do_softirq(void)__u32 pending;int max_restart =MAX_SOFTIRQ_RESTART ;int cpu; +unsigned long pflags = current->flags; + current->flags &= ~PF_MEMALLOC ; pending =local_softirq_pending ();account_system_vtime (current);
@@ -251,6 +253,7 @@ restart:account_system_vtime (current);_local_bh_enable (); +tsk_restore_flags (current, pflags,PF_MEMALLOC ); }#ifndef __ARCH_HAS_DO_SOFTIRQ
include/linux/sched.h +7 -0
@@ -1533,6 +1533,13 @@ static inline void put_task_struct(struc#define tsk_used_math (p) ((p)->flags & PF_USED_MATH)#define used_math () tsk_used_math(current) +static inline void tsk_restore_flags (struct task_struct *p, +unsigned long pflags,unsigned long mask) +{ + p->flags &= ~mask; + p->flags |= pflags & mask; +} +#ifdef CONFIG_SMP extern int set_cpus_allowed_ptr (struct task_struct *p,const cpumask_t *new_mask);
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 8/30 mm: serialize access to min_free_kbytes
In reply to Peter ZijlstraThere is a small race between the procfs caller and the memory hotplug caller of setup_per_zone_pages_min(). Not a big deal, but the next patch will add yet another caller. Time to close the gap.
--- mm/page_alloc.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
mm/page_alloc.c +13 -3
@@ -118,6 +118,7 @@ static char * const zone_names[MAX_NR_ZO "Movable", }; +static DEFINE_SPINLOCK (min_free_lock);int min_free_kbytes =1024 ;unsigned long __meminitdata nr_kernel_pages;
@@ -4333,12 +4334,12 @@ static void setup_per_zone_lowmem_reserv }/** -* setup_per_zone_pages_min - called when min_free_kbytes changes. +* __setup_per_zone_pages_min - called when min_free_kbytes changes. * * Ensures that the pages_{min,low,high} values for each zone are set correctly * with respect to min_free_kbytes. */ -void setup_per_zone_pages_min (void ) +static void __setup_per_zone_pages_min (void ) {unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT -10 );unsigned long lowmem_pages =0 ;
@@ -4433,6 +4434,15 @@ void setup_per_zone_inactive_ratio(void) } } +void setup_per_zone_pages_min (void ) +{ +unsigned long flags; + +spin_lock_irqsave (&min_free_lock, flags); +__setup_per_zone_pages_min (); +spin_unlock_irqrestore (&min_free_lock, flags); +} +/* * Initialise min_free_kbytes. *
@@ -4468,7 +4478,7 @@ static int __init init_per_zone_pages_mi min_free_kbytes =128 ;if (min_free_kbytes >65536 ) min_free_kbytes =65536 ; -setup_per_zone_pages_min (); +__setup_per_zone_pages_min ();setup_per_zone_lowmem_reserve ();setup_per_zone_inactive_ratio ();return 0 ;
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 08/30] mm: serialize access to min_free_kbytes
Quoted 6 lines · Peter Zijlstra
plain text document attachment (mm-setup_per_zone_pages_min.patch) There is a small race between the procfs caller and the memory hotplug caller of
setup_per_zone_pages_min(). Not a big deal, but the next patch will add yet another caller. Time to close the gap.Signed-off-by Peter Zijlstra <[email protected]>
Looks good to me.
Quoted 57 lines
--- mm/page_alloc.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)Index:
linux-2.6/mm/page_alloc.c
===================================================================mm/page_alloc.c +13
-3@@ -118,6 +118,7 @@ static char * const zone_names[MAX_NR_ZO "Movable", }; +static DEFINE_SPINLOCK (min_free_lock);int min_free_kbytes =1024 ;unsigned long __meminitdata nr_kernel_pages;@@ -4333,12 +4334,12 @@ static void setup_per_zone_lowmem_reserv }/** -* setup_per_zone_pages_min - called when min_free_kbytes changes. +* __setup_per_zone_pages_min - called when min_free_kbytes changes. * * Ensures that the pages_{min,low,high} values for each zone are set correctly * with respect to min_free_kbytes. */ -void setup_per_zone_pages_min (void ) +static void __setup_per_zone_pages_min (void ) {unsigned long pages_min = min_free_kbytes >> (PAGE_SHIFT -10 );unsigned long lowmem_pages =0 ;@@ -4433,6 +4434,15 @@ void setup_per_zone_inactive_ratio(void) } } +void setup_per_zone_pages_min (void ) +{ +unsigned long flags; + +spin_lock_irqsave (&min_free_lock, flags); +__setup_per_zone_pages_min (); +spin_unlock_irqrestore (&min_free_lock, flags); +} +/* * Initialise min_free_kbytes. * @@ -4468,7 +4478,7 @@ static int __init init_per_zone_pages_mi min_free_kbytes =128 ;if (min_free_kbytes >65536 ) min_free_kbytes =65536 ; -setup_per_zone_pages_min (); +__setup_per_zone_pages_min ();setup_per_zone_lowmem_reserve ();setup_per_zone_inactive_ratio ();return 0 ;
PATCH 9/30 mm: emergency pool
In reply to Peter ZijlstraProvide means to reserve a specific amount of pages.
The emergency pool is separated from the min watermark because ALLOC_HARDER and ALLOC_HIGH modify the watermark in a relative way and thus do not ensure a strict minimum.
--- include/linux/mmzone.h | 6 ++- mm/page_alloc.c | 84 +++++++++++++++++++++++++++++++++++++++++++------ mm/vmstat.c | 6 +-- 3 files changed, 82 insertions(+), 14 deletions(-)
include/linux/mmzone.h +5 -1
@@ -265,7 +265,10 @@ enum zone_type {struct zone {/* Fields commonly accessed by the page allocator */ -unsigned long pages_min, pages_low, pages_high; +unsigned long pages_high;/* we stop kswapd */ +unsigned long pages_low;/* we wake up kswapd */ +unsigned long pages_min;/* we enter direct reclaim */ +unsigned long pages_emerg;/* emergency pool */ /* * We don't know if the memory that we're going to allocate will be freeable * or/and it will be released eventually, so to avoid totally wasting several
@@ -751,6 +754,7 @@ int sysctl_min_unmapped_ratio_sysctl_han struct file *, void __user *, size_t *, loff_t *);int sysctl_min_slab_ratio_sysctl_handler (struct ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *); +int adjust_memalloc_reserve (int pages);extern int numa_zonelist_order_handler (struct ctl_table *,int ,struct file *,void __user *,size_t *,loff_t *);
mm/page_alloc.c +74 -10
154 lines not on this page · raw message
mm/vmstat.c +3 -3
@@ -785,9 +785,9 @@ static void zoneinfo_show_print(struct s"\n spanned %lu" "\n present %lu" ,zone_page_state (zone,NR_FREE_PAGES ), - zone->pages_min, - zone->pages_low, - zone->pages_high, + zone->pages_emerg + zone->pages_min, + zone->pages_emerg + zone->pages_low, + zone->pages_emerg + zone->pages_high, zone->pages_scanned, zone->lru[LRU_ACTIVE_ANON ].nr_scan, zone->lru[LRU_INACTIVE_ANON].nr_scan,
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 10/30 mm: system wide ALLOC_NO_WATERMARK
In reply to Peter ZijlstraThe reserve is proportionally distributed over all (!highmem) zones in the system. So we need to allow an emergency allocation access to all zones. In order to do that we need to break out of any mempolicy boundaries we might have.
In my opinion that does not break mempolicies as those are user oriented and not system oriented. That is, system allocations are not guaranteed to be within mempolicy boundaries. For instance IRQs don't even have a mempolicy.
So breaking out of mempolicy boundaries for 'rare' emergency allocations, which are always system allocations (as opposed to user) is ok.
--- mm/page_alloc.c | 5 +++++ 1 file changed, 5 insertions(+)
mm/page_alloc.c +5 -0
@@ -1533,6 +1533,11 @@ restart: rebalance:if (alloc_flags &ALLOC_NO_WATERMARKS ) { nofail_alloc: +/* +* break out of mempolicy boundaries +*/ + zonelist =node_zonelist (numa_node_id (), gfp_mask); +/* go through the zonelist yet again, ignoring mins */ page =get_page_from_freelist (gfp_mask, nodemask, order, zonelist, high_zoneidx,ALLOC_NO_WATERMARKS );
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 11/30 mm: __GFP_MEMALLOC
In reply to Peter Zijlstra__GFP_MEMALLOC will allow the allocation to disregard the watermarks, much like PF_MEMALLOC.
It allows one to pass along the memalloc state in object related allocation flags as opposed to task related flags, such as sk->sk_allocation.
--- include/linux/gfp.h | 3 ++- mm/page_alloc.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-)
include/linux/gfp.h +2 -1
@@ -43,6 +43,7 @@ struct vm_area_struct;#define __GFP_REPEAT ((__force gfp_t)0x400u)/* See above */ #define __GFP_NOFAIL ((__force gfp_t)0x800u)/* See above */ #define __GFP_NORETRY ((__force gfp_t)0x1000u)/* See above */ +#define __GFP_MEMALLOC ((__force gfp_t)0x2000u)/* Use emergency reserves */ #define __GFP_COMP ((__force gfp_t)0x4000u)/* Add compound page metadata */ #define __GFP_ZERO ((__force gfp_t)0x8000u)/* Return zeroed page on success */ #define __GFP_NOMEMALLOC ((__force gfp_t)0x10000u)/* Don't use emergency reserves */
@@ -88,7 +89,7 @@ struct vm_area_struct;/* Control page allocator reclaim behavior */ #define GFP_RECLAIM_MASK (__GFP_WAIT|__GFP_HIGH|__GFP_IO|__GFP_FS|\ __GFP_NOWARN|__GFP_REPEAT|__GFP_NOFAIL|\ - __GFP_NORETRY|__GFP_NOMEMALLOC) + __GFP_NORETRY|__GFP_MEMALLOC|__GFP_NOMEMALLOC)/* Control allocation constraints */ #define GFP_CONSTRAINT_MASK (__GFP_HARDWALL|__GFP_THISNODE)
mm/page_alloc.c +3 -1
@@ -1452,7 +1452,9 @@ int gfp_to_alloc_flags(gfp_t gfp_mask) alloc_flags |=ALLOC_HARDER ;if (likely (!(gfp_mask & __GFP_NOMEMALLOC))) { -if (!in_irq () && (p->flags &PF_MEMALLOC )) +if (gfp_mask & __GFP_MEMALLOC) + alloc_flags |=ALLOC_NO_WATERMARKS ; +else if (!in_irq () && (p->flags &PF_MEMALLOC )) alloc_flags |=ALLOC_NO_WATERMARKS ;else if (!in_interrupt () &&unlikely (test_thread_flag (TIF_MEMDIE )))
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 11/30] mm: __GFP_MEMALLOC
Hi Peter,
Quoted 5 lines
__GFP_MEMALLOCwill allow the allocation to disregard the watermarks, much likePF_MEMALLOC.It allows one to pass along the memalloc state in object related allocation flags as opposed to task related flags, such as
sk->sk_allocation.
Is this properly name?
page alloc is always "mem alloc".
you wrote comment as "Use emergency reserves" and this flag works to turn on ALLOC_NO_WATERMARKS.
then, __GFP_NO_WATERMARK or __GFP_EMERGENCY are better?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 11/30] mm: __GFP_MEMALLOC
Quoted 8 lines · KOSAKI Motohiro
Hi Peter,
Quoted 5 lines
__GFP_MEMALLOCwill allow the allocation to disregard the watermarks, much likePF_MEMALLOC.It allows one to pass along the memalloc state in object related allocation flags as opposed to task related flags, such as
sk->sk_allocation.
Quoted 7 lines
Is this properly name?
page alloc is always "mem alloc".you wrote comment as "Use emergency reserves" and
this flag works to turn onALLOC_NO_WATERMARKS.then,
__GFP_NO_WATERMARKor__GFP_EMERGENCYare better?
We've been through this pick a better name thing several times :-/
Yes I agree, __GFP_MEMALLOC is a misnomer, however its consistent with PF_MEMALLOC and __GFP_NOMEMALLOC - of which people know the semantics.
Creating a new name with similar semantics can only serve to confuse.
So unless enough people think its worth renaming all of them, I think we're better off with this name.
Re: [PATCH 11/30] mm: __GFP_MEMALLOC
Quoted 15 lines · KOSAKI Motohiro
Quoted 14 lines
Hi Peter,
Quoted 5 lines
__GFP_MEMALLOCwill allow the allocation to disregard the watermarks, much likePF_MEMALLOC.It allows one to pass along the memalloc state in object related allocation flags as opposed to task related flags, such as
sk->sk_allocation.Is this properly name?
page alloc is always "mem alloc".you wrote comment as "Use emergency reserves" and
this flag works to turn onALLOC_NO_WATERMARKS.
Quoted 8 lines
Quoted 1 line
then,
__GFP_NO_WATERMARKor__GFP_EMERGENCYare better?We've been through this pick a better name thing several times :-/
Yes I agree,
__GFP_MEMALLOCis a misnomer, however its consistent withPF_MEMALLOCand__GFP_NOMEMALLOC- of which people know the semantics.Creating a new name with similar semantics can only serve to confuse.
Ah, understand.
Thanks.
Agreed to __GFP_MEMALLOC.
Quoted 3 lines
So unless enough people think its worth renaming all of them, I think we're better off with this name.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 12/30 mm: memory reserve management
In reply to Peter ZijlstraGeneric reserve management code.
It provides methods to reserve and charge. Upon this, generic alloc/free style reserve pools could be build, which could fully replace mempool_t functionality.
It should also allow for a Banker's algorithm replacement of __GFP_NOFAIL.
--- include/linux/reserve.h | 146 +++++++++++ include/linux/slab.h | 20 - mm/Makefile | 2 mm/reserve.c | 594 ++++++++++++++++++++++++++++++++++++++++++++++++ mm/slub.c | 4 5 files changed, 755 insertions(+), 11 deletions(-)
include/linux/reserve.h new file +146 -0
@@ -0,0 +1,146 @@ +/* +* Memory reserve management. +* +* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <[email protected]> +* +* This file contains the public data structure and API definitions. +*/ + +#ifndef _LINUX_RESERVE_H +#define _LINUX_RESERVE_H + +#include <linux/list.h> +#include <linux/spinlock.h> +#include <linux/wait.h> +#include <linux/slab.h> + +struct mem_reserve { +struct mem_reserve *parent; +struct list_head children; +struct list_head siblings; + +const char *name; + +long pages; +long limit; +long usage; +spinlock_t lock;/* protects limit and usage */ + +wait_queue_head_t waitqueue; +}; + +extern struct mem_reserve mem_reserve_root; + +void mem_reserve_init (struct mem_reserve *res,const char *name, +struct mem_reserve *parent); +int mem_reserve_connect (struct mem_reserve *new_child, +struct mem_reserve *node); +void mem_reserve_disconnect (struct mem_reserve *node); + +int mem_reserve_pages_set (struct mem_reserve *res,long pages); +int mem_reserve_pages_add (struct mem_reserve *res,long pages); +int mem_reserve_pages_charge (struct mem_reserve *res,long pages); + +int mem_reserve_kmalloc_set (struct mem_reserve *res,long bytes); +int mem_reserve_kmalloc_charge (struct mem_reserve *res,long bytes); + +struct kmem_cache ; + +int mem_reserve_kmem_cache_set (struct mem_reserve *res, +struct kmem_cache *s, +int objects); +int mem_reserve_kmem_cache_charge (struct mem_reserve *res, +struct kmem_cache *s,long objs); + +void *___kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg); + +static inline +void *__kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg) +{ +void *obj; + + obj =__kmalloc_node_track_caller (size, + flags | __GFP_NOMEMALLOC | __GFP_NOWARN, node, ip); +if (!obj) + obj =___kmalloc_reserve (size, flags, node, ip, res, emerg); + +return obj; +} + +#define kmalloc_reserve (size, gfp, node, res, emerg) \ + __kmalloc_reserve(size, gfp, node, \ + __builtin_return_address(0), res, emerg) + +void __kfree_reserve (void *obj,struct mem_reserve *res,int emerg); + +static inline +void kfree_reserve (void *obj,struct mem_reserve *res,int emerg) +{ +if (unlikely (obj && res && emerg)) +__kfree_reserve (obj, res, emerg); +else +kfree (obj); +} + +void *__kmem_cache_alloc_reserve (struct kmem_cache *s,gfp_t flags,int node, +struct mem_reserve *res,int *emerg); +static inline +void *kmem_cache_alloc_reserve (struct kmem_cache *s,gfp_t flags,int node, +struct mem_reserve *res,int *emerg) +{ +void *obj; + + obj =kmem_cache_alloc_node (s, + flags | __GFP_NOMEMALLOC | __GFP_NOWARN, node); +if (!obj) + obj =__kmem_cache_alloc_reserve (s, flags, node, res, emerg); + +return obj; +} + +void __kmem_cache_free_reserve (struct kmem_cache *s,void *obj, +struct mem_reserve *res,int emerg); + +static inline +void kmem_cache_free_reserve (struct kmem_cache *s,void *obj, +struct mem_reserve *res,int emerg) +{ +if (unlikely (obj && res && emerg)) +__kmem_cache_free_reserve (s, obj, res, emerg); +else +kmem_cache_free (s, obj); +} + +struct page *__alloc_pages_reserve (int node,gfp_t flags,int order, +struct mem_reserve *res,int *emerg); + +static inline +struct page *alloc_pages_reserve (int node,gfp_t flags,int order, +struct mem_reserve *res,int *emerg) +{ +struct page *page; + + page =alloc_pages_node (node, + flags | __GFP_NOMEMALLOC | __GFP_NOWARN, order); +if (!page) + page =__alloc_pages_reserve (node, flags, order, res, emerg); + +return page; +} + +void __free_pages_reserve (struct page *page,int order, +struct mem_reserve *res,int emerg); + +static inline +void free_pages_reserve (struct page *page,int order, +struct mem_reserve *res,int emerg) +{ +if (unlikely (page && res && emerg)) +__free_pages_reserve (page, order, res, emerg); +else +__free_pages (page, order); +} + +#endif /* _LINUX_RESERVE_H */
mm/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-y := bootmem.o filemap.o mempool.o maccess.o page_alloc.o page-writeback.o pdflush.o \ readahead.o swap.o truncate.o vmscan.o \ prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \ - page_isolation.o $(mmu-y) + page_isolation.o reserve.o $(mmu-y) obj-$(CONFIG_PAGE_WALKER) += pagewalk.o obj-$(CONFIG_BOUNCE) += bounce.o
mm/reserve.c new file +594 -0
594 lines not on this page · raw message
include/linux/slab.h +11 -9
@@ -229,13 +229,14 @@ static inline void *kmem_cache_alloc_nod*/ #if defined(CONFIG_DEBUG_SLAB ) || defined(CONFIG_SLUB )extern void *__kmalloc_track_caller (size_t ,gfp_t ,void *); -#define kmalloc_track_caller (size, flags) \ - __kmalloc_track_caller(size, flags, __builtin_return_address(0))#else -#define kmalloc_track_caller (size, flags) \ +#define __kmalloc_track_caller (size, flags, ip) \ __kmalloc(size, flags)#endif /* DEBUG_SLAB */ +#define kmalloc_track_caller (size, flags) \ + __kmalloc_track_caller(size, flags, __builtin_return_address(0)) +#ifdef CONFIG_NUMA /* * kmalloc_node_track_caller is a special version of kmalloc_node that
@@ -247,21 +248,22 @@ extern void *__kmalloc_track_caller(size*/ #if defined(CONFIG_DEBUG_SLAB ) || defined(CONFIG_SLUB )extern void *__kmalloc_node_track_caller (size_t ,gfp_t ,int ,void *); -#define kmalloc_node_track_caller (size, flags, node) \ - __kmalloc_node_track_caller(size, flags, node, \ - __builtin_return_address(0))#else -#define kmalloc_node_track_caller (size, flags, node) \ +#define __kmalloc_node_track_caller (size, flags, node, ip) \ __kmalloc_node(size, flags, node)#endif #else /* CONFIG_NUMA */ -#define kmalloc_node_track_caller (size, flags, node) \ - kmalloc_track_caller(size, flags) +#define __kmalloc_node_track_caller (size, flags, node, ip) \ + __kmalloc_track_caller(size, flags, ip)#endif /* DEBUG_SLAB */ +#define kmalloc_node_track_caller (size, flags, node) \ + __kmalloc_node_track_caller(size, flags, node, \ + __builtin_return_address(0)) +/* * Shortcuts */
mm/slub.c +3 -1
@@ -2706,6 +2706,7 @@ void *__kmalloc(size_t size, gfp_t flags }EXPORT_SYMBOL (__kmalloc); +#ifdef CONFIG_NUMA static void *kmalloc_large_node (size_t size,gfp_t flags,int node) { struct page *page = alloc_pages_node(node, flags | __GFP_COMP,
@@ -2717,7 +2718,6 @@ static void *kmalloc_large_node(size_t sreturn NULL ; } -#ifdef CONFIG_NUMA void *__kmalloc_node (size_t size,gfp_t flags,int node) {struct kmem_cache *s;
@@ -3303,6 +3303,7 @@ void *__kmalloc_track_caller(size_t sizereturn slab_alloc (s, gfpflags,-1 , caller); } +#ifdef CONFIG_NUMA void *__kmalloc_node_track_caller (size_t size,gfp_t gfpflags,int node,void *caller) {
@@ -3318,6 +3319,7 @@ void *__kmalloc_node_track_caller(size_treturn slab_alloc (s, gfpflags, node, caller); } +#endif #ifdef CONFIG_SLUB_DEBUG static unsigned long count_partial(struct kmem_cache_node *n,
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
Hi Peter,
mm/reserve.c line 460
Quoted 4 lines · Peter Zijlstra
mm/reserve.c new file +4
-0+/* +* alloc wrappers +*/ +
i>>?Hmm, I'm not sure I like the use of __kmalloc_track_caller() (even though you do add the wrappers for SLUB). The functions really are SLAB internals so I'd prefer to see kmalloc_reserve() moved to the allocators.
include/linux/reserve.h line 61
Quoted 3 lines
include/linux/reserve.h new file +3
-0+void *___kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg) +{
This function could use some comments...
Quoted 9 lines
mm/reserve.c new file +9
-0+void *obj; +gfp_t gfp; + + gfp = flags | __GFP_NOMEMALLOC | __GFP_NOWARN; + obj =__kmalloc_node_track_caller (size, gfp, node, ip); + +if (obj || !(gfp_to_alloc_flags (flags) &ALLOC_NO_WATERMARKS )) + goto out; +
mm/reserve.c line 482
Quoted 10 lines
mm/reserve.c new file +10
-0+if (res && !mem_reserve_kmalloc_charge (res, size)) { +if (!(flags & __GFP_WAIT)) + goto out; + +wait_event (res->waitqueue, +mem_reserve_kmalloc_charge (res, size)); + + obj =__kmalloc_node_track_caller (size, gfp, node, ip); +if (obj) { +mem_reserve_kmalloc_charge (res, -size);
Why do we discharge here?
Review
Quoted 2 lines
(quoted diff) +2
-0+ goto out; + }
If the allocation fails, we try again (but nothing has changed, right?). Why?
mm/reserve.c line 488
Quoted 4 lines
mm/reserve.c new file +4
-0+ } + + obj =__kmalloc_node_track_caller (size, flags, node, ip); +WARN_ON (!obj);
Why don't we discharge from the reserve here if !obj?
mm/reserve.c line 496
Quoted 8 lines
mm/reserve.c new file +8
-0+if (emerg) + *emerg |=1 ; + +out: +return obj; +} + +void __kfree_reserve (void *obj,struct mem_reserve *res,int emerg)
I don't see 'emerg' used anywhere.
mm/reserve.c line 500
Quoted 4 lines
mm/reserve.c new file +4
-0+{ +size_t size =ksize (obj); + +kfree (obj);
We're trying to get rid of kfree() so I'd __kfree_reserve() could to mm/sl?b.c. Matt, thoughts?
mm/reserve.c line 507
Quoted 8 lines
mm/reserve.c new file +7
-0+/* +* ksize gives the full allocated size vs the requested size we used to +* charge; however since we round up to the nearest power of two, this +* should all work nicely. +*/ +mem_reserve_kmalloc_charge (res, -size); +}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
Quoted 12 lines · Pekka Enberg
Hi Peter,
mm/reserve.c line 460
Quoted 4 lines · Peter Zijlstra
mm/reserve.c new file +4
-0+/* +* alloc wrappers +*/ +i>>?Hmm, I'm not sure I like the use of
__kmalloc_track_caller()(even though you do add the wrappers for SLUB). The functions really are SLAB internals so I'd prefer to seekmalloc_reserve()moved to the allocators.
See below..
Quoted 5 lines
include/linux/reserve.h line 61
Quoted 3 lines
include/linux/reserve.h new file +3
-0+void *___kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg) +{This function could use some comments...
Yes, my latest does have those.. let me paste the relevant bit:
+void *___kmalloc_reserve(size_t size, gfp_t flags, int node, void *ip,
+ struct mem_reserve *res, int *emerg)
+{
+ void *obj;
+ gfp_t gfp;
+
+ /*
+ * Try a regular allocation, when that fails and we're not entitled + * to the reserves, fail. + */
+ gfp = flags | __GFP_NOMEMALLOC | __GFP_NOWARN;
+ obj = __kmalloc_node_track_caller(size, gfp, node, ip);
+
+ if (obj || !(gfp_to_alloc_flags(flags) & ALLOC_NO_WATERMARKS))
+ goto out;
+
+ /*
+ * If we were given a reserve to charge against, try that.
+ */
+ if (res && !mem_reserve_kmalloc_charge(res, size)) {
+ /*
+ * If we failed to charge and we're not allowed to wait for + * it to succeed, bail. + */
+ if (!(flags & __GFP_WAIT))
+ goto out;
+
+ /*
+ * Wait for a successfull charge against the reserve. All + * uncharge operations against this reserve will wake us up. + */
+ wait_event(res->waitqueue,
+ mem_reserve_kmalloc_charge(res, size));
+
+ /*
+ * After waiting for it, again try a regular allocation. + * Pressure could have lifted during our sleep. If this + * succeeds, uncharge the reserve. + */
+ obj = __kmalloc_node_track_caller(size, gfp, node, ip);
+ if (obj) {
+ mem_reserve_kmalloc_charge(res, -size);
+ goto out;
+ }
+ }
+
+ /*
+ * Regular allocation failed, and we've successfully charged our + * requested usage against the reserve. Do the emergency allocation. + */ + obj = __kmalloc_node_track_caller(size, flags, node, ip); + WARN_ON(!obj); + if (emerg)
+ *emerg |= 1;
+
+out:
+ return obj;
+}
Quoted 13 lines
Quoted 13 lines
mm/reserve.c new file +13
-0+void *obj; +gfp_t gfp; + + gfp = flags | __GFP_NOMEMALLOC | __GFP_NOWARN; + obj =__kmalloc_node_track_caller (size, gfp, node, ip); + +if (obj || !(gfp_to_alloc_flags (flags) &ALLOC_NO_WATERMARKS )) + goto out; + +if (res && !mem_reserve_kmalloc_charge (res, size)) { +if (!(flags & __GFP_WAIT)) + goto out; +
Quoted 8 lines
mm/reserve.c line 482
Quoted 6 lines
mm/reserve.c new file +6
-0+wait_event (res->waitqueue, +mem_reserve_kmalloc_charge (res, size)); + + obj =__kmalloc_node_track_caller (size, gfp, node, ip); +if (obj) { +mem_reserve_kmalloc_charge (res, -size);Why do we discharge here?
because a regular allocation succeeded.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ goto out; + }If the allocation fails, we try again (but nothing has changed, right?). Why?
Note the different allocation flags for the two allocations.
Quoted 6 lines
mm/reserve.c line 488
Quoted 4 lines
mm/reserve.c new file +4
-0+ } + + obj =__kmalloc_node_track_caller (size, flags, node, ip); +WARN_ON (!obj);Why don't we discharge from the reserve here if !obj?
Well, this allocation should never fail:
- we reserved memory
- we accounted/throttle its usage
Thus this allocation should always succeed.
Quoted 10 lines
mm/reserve.c line 496
Quoted 8 lines
mm/reserve.c new file +8
-0+if (emerg) + *emerg |=1 ; + +out: +return obj; +} + +void __kfree_reserve (void *obj,struct mem_reserve *res,int emerg)I don't see 'emerg' used anywhere.
Patch 19/30 has:
- data = kmalloc_node_track_caller(size + sizeof(struct skb_shared_info),
- gfp_mask, node);
+ data = kmalloc_reserve(size + sizeof(struct skb_shared_info),
+ gfp_mask, node, &net_skb_reserve, &emergency);
if (!data)
goto nodata;@@ -205,6 +211,7 @@ struct sk_buff *__alloc_skb(unsigned int
* the tail pointer in struct sk_buff!
*/
memset(skb, 0, offsetof(struct sk_buff, tail));
+ skb->emergency = emergency;
skb->truesize = size + sizeof(struct sk_buff);
atomic_set(&skb->users, 1);
skb->head = data;Quoted 7 lines
mm/reserve.c line 500
Quoted 4 lines
mm/reserve.c new file +4
-0+{ +size_t size =ksize (obj); + +kfree (obj);We're trying to get rid of
kfree()so I'd__kfree_reserve()could to mm/sl?b.c. Matt, thoughts?
My issue with moving these helpers into mm/sl?b.c is that it would require replicating all this code 3 times. Even though the functionality is (or should) be invariant to the actual slab implementation.
Quoted 9 lines
mm/reserve.c line 507
Quoted 8 lines
mm/reserve.c new file +7
-0+/* +* ksize gives the full allocated size vs the requested size we used to +* charge; however since we round up to the nearest power of two, this +* should all work nicely. +*/ +mem_reserve_kmalloc_charge (res, -size); +}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
Hi Peter,
Quoted 72 lines · Peter Zijlstra
Quoted 12 lines · Pekka Enberg
Hi Peter,
mm/reserve.c line 460
Quoted 4 lines · Peter Zijlstra
mm/reserve.c new file +4
-0+/* +* alloc wrappers +*/ +i>>?Hmm, I'm not sure I like the use of
__kmalloc_track_caller()(even though you do add the wrappers for SLUB). The functions really are SLAB internals so I'd prefer to seekmalloc_reserve()moved to the allocators.See below..
Quoted 5 lines
include/linux/reserve.h line 61
Quoted 3 lines
include/linux/reserve.h new file +3
-0+void *___kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg) +{This function could use some comments...
Yes, my latest does have those.. let me paste the relevant bit:
mm/reserve.c new file +48
-0+void *___kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg) +{ +void *obj; +gfp_t gfp; + +/* +* Try a regular allocation, when that fails and we're not entitled +* to the reserves, fail. +*/ + gfp = flags | __GFP_NOMEMALLOC | __GFP_NOWARN; + obj =__kmalloc_node_track_caller (size, gfp, node, ip); + +if (obj || !(gfp_to_alloc_flags (flags) &ALLOC_NO_WATERMARKS )) + goto out; + +/* +* If we were given a reserve to charge against, try that. +*/ +if (res && !mem_reserve_kmalloc_charge (res, size)) { +/* +* If we failed to charge and we're not allowed to wait for +* it to succeed, bail. +*/ +if (!(flags & __GFP_WAIT)) + goto out; + +/* +* Wait for a successfull charge against the reserve. All +* uncharge operations against this reserve will wake us up. +*/ +wait_event (res->waitqueue, +mem_reserve_kmalloc_charge (res, size)); + +/* +* After waiting for it, again try a regular allocation. +* Pressure could have lifted during our sleep. If this +* succeeds, uncharge the reserve. +*/ + obj =__kmalloc_node_track_caller (size, gfp, node, ip); +if (obj) { +mem_reserve_kmalloc_charge (res, -size); + goto out; + } + } + +/* +* Regular allocation failed, and we've successfully charged our
mm/reserve.c line 543
Quoted 10 lines
mm/reserve.c new file +10
-0+* requested usage against the reserve. Do the emergency allocation. +*/ + obj =__kmalloc_node_track_caller (size, flags, node, ip); +WARN_ON (!obj); +if (emerg) + *emerg |=1 ; + +out: +return obj; +}
Heh, indeed, looks much better :-).
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
mm/reserve.c new file +13
-0+void *obj; +gfp_t gfp; + + gfp = flags | __GFP_NOMEMALLOC | __GFP_NOWARN; + obj =__kmalloc_node_track_caller (size, gfp, node, ip); + +if (obj || !(gfp_to_alloc_flags (flags) &ALLOC_NO_WATERMARKS )) + goto out; + +if (res && !mem_reserve_kmalloc_charge (res, size)) { +if (!(flags & __GFP_WAIT)) + goto out; +Quoted 8 lines
mm/reserve.c line 482
Quoted 6 lines
mm/reserve.c new file +6
-0+wait_event (res->waitqueue, +mem_reserve_kmalloc_charge (res, size)); + + obj =__kmalloc_node_track_caller (size, gfp, node, ip); +if (obj) { +mem_reserve_kmalloc_charge (res, -size);Why do we discharge here?
because a regular allocation succeeded.
Quoted 7 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ goto out; + }If the allocation fails, we try again (but nothing has changed, right?). Why?
Note the different allocation flags for the two allocations.
Uhm, yeah. I missed that.
Quoted 7 lines
Quoted 6 lines
mm/reserve.c line 488
Quoted 4 lines
mm/reserve.c new file +4
-0+ } + + obj =__kmalloc_node_track_caller (size, flags, node, ip); +WARN_ON (!obj);Why don't we discharge from the reserve here if !obj?
Quoted 5 lines
Well, this allocation should never fail:
- we reserved memory
- we accounted/throttle its usageThus this allocation should always succeed.
But if it *does* fail, it doesn't help that we mess up the reservation counts, no?
Quoted 37 lines
Quoted 10 lines
mm/reserve.c line 496
Quoted 8 lines
mm/reserve.c new file +8
-0+if (emerg) + *emerg |=1 ; + +out: +return obj; +} + +void __kfree_reserve (void *obj,struct mem_reserve *res,int emerg)I don't see 'emerg' used anywhere.
Patch 19/30 has:
(quoted diff) +3
-2- data = kmalloc_node_track_caller(size + sizeof(struct skb_shared_info), - gfp_mask, node); + data = kmalloc_reserve(size + sizeof(struct skb_shared_info), + gfp_mask, node, &net_skb_reserve, &emergency); if (!data) goto nodata;@@ -205,6 +211,7 @@ struct sk_buff *__alloc_skb(unsigned int * the tail pointer in struct sk_buff! */ memset(skb, 0, offsetof(struct sk_buff, tail)); + skb->emergency = emergency; skb->truesize = size + sizeof(struct sk_buff); atomic_set(&skb->users, 1); skb->head = data;Quoted 8 lines
mm/reserve.c line 500
Quoted 5 lines
mm/reserve.c new file +4
-0+{ +size_t size =ksize (obj); + +kfree (obj);We're trying to get rid of
kfree()so I'd__kfree_reserve()could to mm/sl?b.c. Matt, thoughts?
Quoted 3 lines
My issue with moving these helpers into mm/sl?b.c is that it would require replicating all this code 3 times. Even though the functionality is (or should) be invariant to the actual slab implementation.
Right, I guess we could just rename ksize() to something else then and keep it internal to mm/.
Quoted 10 lines
Quoted 9 lines
mm/reserve.c line 507
Quoted 8 lines
mm/reserve.c new file +7
-0+/* +* ksize gives the full allocated size vs the requested size we used to +* charge; however since we round up to the nearest power of two, this +* should all work nicely. +*/ +mem_reserve_kmalloc_charge (res, -size); +}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
Quoted 7 lines · Pekka Enberg
Quoted 7 lines
Quoted 6 lines
mm/reserve.c line 488
Quoted 4 lines
mm/reserve.c new file +4
-0+ } + + obj =__kmalloc_node_track_caller (size, flags, node, ip); +WARN_ON (!obj);Why don't we discharge from the reserve here if !obj?
Quoted 8 lines
Quoted 5 lines
Well, this allocation should never fail:
- we reserved memory
- we accounted/throttle its usageThus this allocation should always succeed.
But if it *does* fail, it doesn't help that we mess up the reservation counts, no?
I guess you're right there. Will fix. Thanks!
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
mm/reserve.c line 500
Quoted 4 lines
mm/reserve.c new file +4
-0+{ +size_t size =ksize (obj); + +kfree (obj);We're trying to get rid of
kfree()so I'd__kfree_reserve()could to mm/sl?b.c. Matt, thoughts?
Quoted 6 lines
Quoted 3 lines
My issue with moving these helpers into mm/sl?b.c is that it would require replicating all this code 3 times. Even though the functionality is (or should) be invariant to the actual slab implementation.
Right, I guess we could just rename
ksize()to something else then and keep it internal tomm/.
That would be nice - we can stuff it into mm/internal.h or somesuch.
Also, you might have noticed, I still need to do everything SLOB. The last time I rewrote all this code I was still hoping Linux would 'soon' have a single slab allocator, but evidently we're still going with 3 for now.. :-/
So I guess I can no longer hide behind that and will have to bite the bullet and write the SLOB bits..
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
mm/reserve.c line 507
Quoted 7 lines
mm/reserve.c new file +7
-0+/* +* ksize gives the full allocated size vs the requested size we used to +* charge; however since we round up to the nearest power of two, this +* should all work nicely. +*/ +mem_reserve_kmalloc_charge (res, -size); +}
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
Hi Peter,
Quoted 7 lines · Peter Zijlstra
Also, you might have noticed, I still need to do everything SLOB. The last time I rewrote all this code I was still hoping Linux would 'soon' have a single slab allocator, but evidently we're still going with 3 for now.. :-/
So I guess I can no longer hide behind that and will have to bite the bullet and write the SLOB bits..
Oh, I don't expect SLOB to go away anytime soon. We are still trying to get rid of SLAB, though, but there are some TPC regressions that we don't have a reproducible test case for so that effort has stalled a bit.
Pekka
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
In reply to Peter ZijlstraQuoted 7 lines · Peter Zijlstra
Also, you might have noticed, I still need to do everything SLOB. The last time I rewrote all this code I was still hoping Linux would 'soon' have a single slab allocator, but evidently we're still going with 3 for now.. :-/
So I guess I can no longer hide behind that and will have to bite the bullet and write the SLOB bits..
i>>?I haven't seen the rest of this thread, but I presume this is part of your OOM-avoidance for network I/O framework?
SLOB can be pretty easily expanded to handle a notion of independent allocation arenas as there are only a couple global variables to switch between. i>>?kfree will also return allocations to the page list (and therefore arena) from whence they came. That may make it pretty simple to create and prepopulate reserve pools.
Signature · 7 lines
Mathematics is the supreme nostalgia of our time. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
Quoted 11 lines · Matt Mackall
Quoted 7 lines · Peter Zijlstra
Also, you might have noticed, I still need to do everything SLOB. The last time I rewrote all this code I was still hoping Linux would 'soon' have a single slab allocator, but evidently we're still going with 3 for now.. :-/
So I guess I can no longer hide behind that and will have to bite the bullet and write the SLOB bits..
i>>?I haven't seen the rest of this thread, but I presume this is part of your OOM-avoidance for network I/O framework?
Yes indeed.
Quoted 5 lines
SLOB can be pretty easily expanded to handle a notion of independent allocation arenas as there are only a couple global variables to switch between. i>>?kfree will also return allocations to the page list (and therefore arena) from whence they came. That may make it pretty simple to create and prepopulate reserve pools.
Right - currently we let all the reserves sit on the free page list. The advantage there is that it also helps the anti-frag stuff, due to having larger free lists.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
In reply to Pekka EnbergQuoted 2 lines · Pekka Enberg
We're trying to get rid of
kfree()so I'd__kfree_reserve()could to mm/sl?b.c. Matt, thoughts?
I think you mean ksize there. My big issue is that we need to make it clear that ksize pairs -only- with kmalloc and that ksize(kmem_cache_alloc(...)) is a categorical error. Preferably, we do this by giving it a distinct name, like kmalloc_size(). We can stick an underbar in front of it to suggest you ought not be using it too.
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* + * ksize gives the full allocated size vs the requested size weused to
Review
Quoted 1 line
(quoted diff) +1
-0+ * charge; however since we round up to the nearest power of two,this
mm/reserve.c line 505
Quoted 2 lines
mm/reserve.c new file +2
-0+* should all work nicely. +*/
SLOB doesn't do this, of course. But does that matter? I think you want to charge the actual allocation size to the reserve in all cases, no? That probably means calling ksize() on both alloc and free.
Signature · 7 lines
Mathematics is the supreme nostalgia of our time. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
Quoted 9 lines · Matt Mackall
Quoted 2 lines · Pekka Enberg
We're trying to get rid of
kfree()so I'd__kfree_reserve()could to mm/sl?b.c. Matt, thoughts?I think you mean ksize there. My big issue is that we need to make it clear that ksize pairs -only- with kmalloc and that ksize(kmem_cache_alloc(...)) is a categorical error. Preferably, we do this by giving it a distinct name, like
kmalloc_size(). We can stick an underbar in front of it to suggest you ought not be using it too.
Right, both make sense, so _kmalloc_size() has my vote.
Quoted 11 lines
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* + * ksize gives the full allocated size vs the requested size weused to
Review
Quoted 1 line
(quoted diff) +1
-0+ * charge; however since we round up to the nearest power of two,this
mm/reserve.c line 505
Quoted 2 lines
mm/reserve.c new file +2
-0+* should all work nicely. +*/ SLOB doesn't do this, of course. But does that matter? I think you want to charge the actual allocation size to the reserve in all cases, no? That probably means calling
ksize()on both alloc and free.
Like said, I still need to do all the SLOB reservation stuff. That includes coming up with upper bound fragmentation loss.
For SL[UA]B I use roundup_power_of_two for kmalloc sizes. Thus with the above ksize(), if we did p=kmalloc(x), then we'd account roundup_power_of_two(x), and that should be equal to roundup_power_of_two(ksize(p)), as ksize will always be smaller or equal to the roundup.
I'm guessing the power of two upper bound is good for SLOB too - although I haven't tried proving it wrong or tighetening it.
Only the kmem_cache_* reservation stuff would need some extra attention with SLOB.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
In reply to Peter ZijlstraQuoted 5 lines · On Thursday July 24, [email protected] wrote:
Generic reserve management code.
It provides methods to reserve and charge. Upon this, generic alloc/free style reserve pools could be build, which could fully replace
mempool_tfunctionality.
This looks quite different to last time I looked at the code (I think).
You now have a more structured "kmalloc_reserve" interface which returns a flag to say if the allocation was from an emergency pool. I think this will be a distinct improvement at the call sites, though I haven't looked at them yet. :-)
include/linux/reserve.h line 27
Quoted 12 lines
include/linux/reserve.h new file +12
-0+ +struct mem_reserve { +struct mem_reserve *parent; +struct list_head children; +struct list_head siblings; + +const char *name; + +long pages; +long limit; +long usage; +spinlock_t lock;/* protects limit and usage */
^^^^^
Quoted 3 lines
include/linux/reserve.h new file +3
-0+ +wait_queue_head_t waitqueue; +};
....
Quoted 4 lines
mm/reserve.c new file +4
-0+static void __calc_reserve (struct mem_reserve *res,long pages,long limit) +{ +unsigned long flags; +
mm/reserve.c line 100
Quoted 10 lines
mm/reserve.c new file +10
-0+for ( ; res; res = res->parent) { + res->pages += pages; + +if (limit) { +spin_lock_irqsave (&res->lock, flags); + res->limit += limit; +spin_unlock_irqrestore (&res->lock, flags); + } + } +}
I cannot figure out why the spinlock is being used to protect updates to 'limit'.
As far as I can see, mem_reserve_mutex already protects all those updates.
Certainly we need the spinlock for usage, but why for limit??
Quoted 4 lines
include/linux/reserve.h new file +4
-0+ +void *___kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg) +{
....
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (emerg) + *emerg |= 1;
Why not just
if (emerg) *emerg = 1.
I can't we where '*emerg' can have any value but 0 or 1, so the '|' is pointless ???
Thanks,
NeilBrown
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
Quoted 45 lines · Neil Brown
Quoted 5 lines · On Thursday July 24, [email protected] wrote:
Generic reserve management code.
It provides methods to reserve and charge. Upon this, generic alloc/free style reserve pools could be build, which could fully replace
mempool_tfunctionality.This looks quite different to last time I looked at the code (I think).
You now have a more structured "
kmalloc_reserve" interface which returns a flag to say if the allocation was from an emergency pool. I think this will be a distinct improvement at the call sites, though I haven't looked at them yet. :-)include/linux/reserve.h line 27
Quoted 12 lines
include/linux/reserve.h new file +12
-0+ +struct mem_reserve { +struct mem_reserve *parent; +struct list_head children; +struct list_head siblings; + +const char *name; + +long pages; +long limit; +long usage; +spinlock_t lock;/* protects limit and usage */ ^^^^^Quoted 3 lines
include/linux/reserve.h new file +3
-0+ +wait_queue_head_t waitqueue; +};.....
Quoted 12 lines
mm/reserve.c new file +12
-0+static void __calc_reserve (struct mem_reserve *res,long pages,long limit) +{ +unsigned long flags; + +for ( ; res; res = res->parent) { + res->pages += pages; + +if (limit) { +spin_lock_irqsave (&res->lock, flags); + res->limit += limit; +spin_unlock_irqrestore (&res->lock, flags); + }
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ } +}I cannot figure out why the spinlock is being used to protect updates to 'limit'.
As far as I can see,mem_reserve_mutexalready protects all those updates.
Certainly we need the spinlock for usage, but why for limit??
against __mem_reserve_charge(), granted, the race would be minimal at best - but it seemed better this way.
Quoted 10 lines
Quoted 4 lines
include/linux/reserve.h new file +4
-0+ +void *___kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg) +{.....
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (emerg) + *emerg |= 1;Why not just
Quoted 5 lines
if (emerg) *emerg = 1.I can't we where '*emerg' can have any value but 0 or 1, so the '|' is pointless ???
weirdness in my brain when I wrote that I guess, shall ammend!
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
In reply to Peter ZijlstraQuoted 5 lines · On Thursday July 24, [email protected] wrote:
Generic reserve management code.
It provides methods to reserve and charge. Upon this, generic alloc/free style reserve pools could be build, which could fully replace
mempool_tfunctionality.
More comments on this patch .....
Quoted 21 lines
include/linux/reserve.h new file +21
-0+void *___kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg); + +static inline +void *__kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg) +{ +void *obj; + + obj =__kmalloc_node_track_caller (size, + flags | __GFP_NOMEMALLOC | __GFP_NOWARN, node, ip); +if (!obj) + obj =___kmalloc_reserve (size, flags, node, ip, res, emerg); + +return obj; +} + +#define kmalloc_reserve (size, gfp, node, res, emerg) \ + __kmalloc_reserve(size, gfp, node, \ + __builtin_return_address(0), res, emerg) +
.....
Quoted 28 lines
mm/reserve.c new file +28
-0+/* +* alloc wrappers +*/ + +void *___kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg) +{ +void *obj; +gfp_t gfp; + + gfp = flags | __GFP_NOMEMALLOC | __GFP_NOWARN; + obj =__kmalloc_node_track_caller (size, gfp, node, ip); + +if (obj || !(gfp_to_alloc_flags (flags) &ALLOC_NO_WATERMARKS )) + goto out; + +if (res && !mem_reserve_kmalloc_charge (res, size)) { +if (!(flags & __GFP_WAIT)) + goto out; + +wait_event (res->waitqueue, +mem_reserve_kmalloc_charge (res, size)); + + obj =__kmalloc_node_track_caller (size, gfp, node, ip); +if (obj) { +mem_reserve_kmalloc_charge (res, -size); + goto out; + }
mm/reserve.c line 494
Quoted 10 lines
mm/reserve.c new file +10
-0+ } + + obj =__kmalloc_node_track_caller (size, flags, node, ip); +WARN_ON (!obj); +if (emerg) + *emerg |=1 ; + +out: +return obj; +}
Two comments to be precise.
1/ __kmalloc_reserve attempts a __GFP_NOMEMALLOC allocation, and then
if that fails, ___kmalloc_reserve immediately tries again. Is that pointless? Should the second one be removed?
2/ mem_reserve_kmalloc_charge appears to assume that the 'mem_reserve'
has been 'connected' and so is active.
While callers probably only set GFP_MEMALLOC in cases where the mem_reserve is connected, ALLOC_NO_WATERMARKS could get via PF_MEMALLOC so we could end up calling mem_reserve_kmalloc_charge when the mem_reserve is not connected.
That seems to be 'odd' at least.
It might even be 'wrong' as mem_reserve_connect doesn't add the usage of the child to the parent - only the ->pages and ->limit.
What is your position on this? Mine is "still slightly confused".
NeilBrown
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 12/30] mm: memory reserve management
Quoted 72 lines · Neil Brown
Quoted 5 lines · On Thursday July 24, [email protected] wrote:
Generic reserve management code.
It provides methods to reserve and charge. Upon this, generic alloc/free style reserve pools could be build, which could fully replace
mempool_tfunctionality.More comments on this patch .....
Quoted 21 lines
include/linux/reserve.h new file +21
-0+void *___kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg); + +static inline +void *__kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg) +{ +void *obj; + + obj =__kmalloc_node_track_caller (size, + flags | __GFP_NOMEMALLOC | __GFP_NOWARN, node, ip); +if (!obj) + obj =___kmalloc_reserve (size, flags, node, ip, res, emerg); + +return obj; +} + +#define kmalloc_reserve (size, gfp, node, res, emerg) \ + __kmalloc_reserve(size, gfp, node, \ + __builtin_return_address(0), res, emerg) +......
Quoted 28 lines
mm/reserve.c new file +28
-0+/* +* alloc wrappers +*/ + +void *___kmalloc_reserve (size_t size,gfp_t flags,int node,void *ip, +struct mem_reserve *res,int *emerg) +{ +void *obj; +gfp_t gfp; + + gfp = flags | __GFP_NOMEMALLOC | __GFP_NOWARN; + obj =__kmalloc_node_track_caller (size, gfp, node, ip); + +if (obj || !(gfp_to_alloc_flags (flags) &ALLOC_NO_WATERMARKS )) + goto out; + +if (res && !mem_reserve_kmalloc_charge (res, size)) { +if (!(flags & __GFP_WAIT)) + goto out; + +wait_event (res->waitqueue, +mem_reserve_kmalloc_charge (res, size)); + + obj =__kmalloc_node_track_caller (size, gfp, node, ip); +if (obj) { +mem_reserve_kmalloc_charge (res, -size); + goto out; + }mm/reserve.c line 494
Quoted 10 lines
mm/reserve.c new file +10
-0+ } + + obj =__kmalloc_node_track_caller (size, flags, node, ip); +WARN_ON (!obj); +if (emerg) + *emerg |=1 ; + +out: +return obj; +}Two comments to be precise.
Quoted 3 lines
1/
__kmalloc_reserveattempts a__GFP_NOMEMALLOCallocation, and then
if that fails,___kmalloc_reserveimmediately tries again. Is that pointless? Should the second one be removed?
Pretty pointless yes, except that it made ___kmalloc_reserve a nicer function to read, and as its an utter slow path I couldn't be arsed to optimize :-)
Quoted 2 lines
2/
mem_reserve_kmalloc_chargeappears to assume that the 'mem_reserve'
has been 'connected' and so is active.
Hmm, that would be __mem_reserve_charge() then, because the callers don't do much.
Quoted 4 lines
While callers probably only set
GFP_MEMALLOCin cases where themem_reserveis connected,ALLOC_NO_WATERMARKScould get viaPF_MEMALLOCso we could end up callingmem_reserve_kmalloc_chargewhen themem_reserveis not connected.
Right..
Quoted 5 lines
That seems to be 'odd' at least.
It might even be 'wrong' asmem_reserve_connectdoesn't add the usage of the child to the parent - only the ->pages and ->limit.What is your position on this? Mine is "still slightly confused".
Uhmm,. good point. Let me ponder this while I go for breakfast ;-)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 13/30 selinux: tag avc cache alloc as non-critical
In reply to Peter ZijlstraFailing to allocate a cache entry will only harm performance not correctness. Do not consume valuable reserve pages for something like that.
--- security/selinux/avc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/selinux/avc.c +1 -1
@@ -334,7 +334,7 @@ static struct avc_node *avc_alloc_node(v {struct avc_node *node; - node =kmem_cache_zalloc (avc_node_cachep,GFP_ATOMIC ); + node =kmem_cache_zalloc (avc_node_cachep,GFP_ATOMIC |__GFP_NOMEMALLOC);if (!node) goto out;
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 14/30 net: wrap sk->sk_backlog_rcv()
In reply to Peter ZijlstraWrap calling sk->sk_backlog_rcv() in a function. This will allow extending the generic sk_backlog_rcv behaviour.
--- include/net/sock.h | 5 +++++ include/net/tcp.h | 2 +- net/core/sock.c | 4 ++-- net/ipv4/tcp.c | 2 +- net/ipv4/tcp_timer.c | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-)
include/net/sock.h +5 -0
@@ -482,6 +482,11 @@ static inline void sk_add_backlog(struct skb->next =NULL ; } +static inline int sk_backlog_rcv (struct sock *sk,struct sk_buff *skb) +{ +return sk->sk_backlog_rcv (sk, skb); +} +#define sk_wait_event (__sk, __timeo, __condition) \ ({ int __rc; \ release_sock(__sk); \
net/core/sock.c +2 -2
@@ -326,7 +326,7 @@ int sk_receive_skb(struct sock *sk, stru*/ mutex_acquire (&sk->sk_lock.dep_map,0 ,1 , _RET_IP_); - rc = sk->sk_backlog_rcv (sk, skb); + rc =sk_backlog_rcv (sk, skb);mutex_release (&sk->sk_lock.dep_map,1 , _RET_IP_); }else
@@ -1373,7 +1373,7 @@ static void __release_sock(struct sock *struct sk_buff *next = skb->next; skb->next =NULL ; - sk->sk_backlog_rcv (sk, skb); +sk_backlog_rcv (sk, skb);/* * We are in process context here with softirqs
net/ipv4/tcp.c +1 -1
@@ -1161,7 +1161,7 @@ static void tcp_prequeue_process(struct* necessary */ local_bh_disable ();while ((skb =__skb_dequeue (&tp->ucopy.prequeue)) !=NULL ) - sk->sk_backlog_rcv (sk, skb); +sk_backlog_rcv (sk, skb);local_bh_enable ();/* Clear memory counter. */
net/ipv4/tcp_timer.c +1 -1
@@ -203,7 +203,7 @@ static void tcp_delack_timer(unsigned loNET_INC_STATS_BH (LINUX_MIB_TCPSCHEDULERFAILED );while ((skb =__skb_dequeue (&tp->ucopy.prequeue)) !=NULL ) - sk->sk_backlog_rcv (sk, skb); +sk_backlog_rcv (sk, skb); tp->ucopy.memory =0 ; }
include/net/tcp.h +1 -1
@@ -893,7 +893,7 @@ static inline int tcp_prequeue(struct soBUG_ON (sock_owned_by_user (sk));while ((skb1 =__skb_dequeue (&tp->ucopy.prequeue)) !=NULL ) { - sk->sk_backlog_rcv (sk, skb1); +sk_backlog_rcv (sk, skb1);NET_INC_STATS_BH (LINUX_MIB_TCPPREQUEUEDROPPED ); }
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 15/30 net: packet split receive api
In reply to Peter ZijlstraAdd some packet-split receive hooks.
For one this allows to do NUMA node affine page allocs. Later on these hooks will be extended to do emergency reserve allocations for fragments.
--- drivers/net/bnx2.c | 8 +++----- drivers/net/e1000/e1000_main.c | 8 ++------ drivers/net/e1000e/netdev.c | 7 ++----- drivers/net/igb/igb_main.c | 8 ++------ drivers/net/ixgbe/ixgbe_main.c | 10 +++------- drivers/net/sky2.c | 16 ++++++---------- include/linux/skbuff.h | 23 +++++++++++++++++++++++ net/core/skbuff.c | 20 ++++++++++++++++++++ 8 files changed, 61 insertions(+), 39 deletions(-)
drivers/net/e1000/e1000_main.c +2 -6
@@ -4492,12 +4492,8 @@ e1000_clean_rx_irq_ps(struct e1000_adaptpci_unmap_page (pdev, ps_page_dma->ps_page_dma[j],PAGE_SIZE ,PCI_DMA_FROMDEVICE ); ps_page_dma->ps_page_dma[j] =0 ; -skb_fill_page_desc (skb, j, ps_page->ps_page[j],0 , - length); +skb_add_rx_frag (skb, j, ps_page->ps_page[j],0 , length); ps_page->ps_page[j] =NULL ; - skb->len += length; - skb->data_len += length; - skb->truesize += length; }/* strip the ethernet crc, problem is we're using pages now so
@@ -4705,7 +4701,7 @@ e1000_alloc_rx_buffers_ps(struct e1000_aif (j < adapter->rx_ps_pages) {if (likely (!ps_page->ps_page[j])) { ps_page->ps_page[j] = -alloc_page (GFP_ATOMIC ); +netdev_alloc_page (netdev);if (unlikely (!ps_page->ps_page[j])) { adapter->alloc_rx_buff_failed++; goto no_buffers;
include/linux/skbuff.h +23 -0
@@ -824,6 +824,9 @@ static inline void skb_fill_page_desc(stskb_shinfo (skb)->nr_frags = i +1 ; } +extern void skb_add_rx_frag (struct sk_buff *skb,int i,struct page *page, +int off,int size); +#define SKB_PAGE_ASSERT (skb) BUG_ON(skb_shinfo(skb)->nr_frags)#define SKB_FRAG_ASSERT (skb) BUG_ON(skb_shinfo(skb)->frag_list)#define SKB_LINEAR_ASSERT (skb) BUG_ON(skb_is_nonlinear(skb))
@@ -1238,6 +1241,26 @@ static inline struct sk_buff *netdev_allreturn __netdev_alloc_skb (dev, length,GFP_ATOMIC ); } +extern struct page *__netdev_alloc_page (struct net_device *dev,gfp_t gfp_mask); + +/** +* netdev_alloc_page - allocate a page for ps-rx on a specific device +* @dev: network device to receive on +* +* Allocate a new page node local to the specified device. +* +* %NULL is returned if there is no free memory. +*/ +static inline struct page *netdev_alloc_page (struct net_device *dev) +{ +return __netdev_alloc_page (dev,GFP_ATOMIC ); +} + +static inline void netdev_free_page (struct net_device *dev,struct page *page) +{ +__free_page (page); +} +/** * skb_clone_writable - is the header of a clone writable * @skb: buffer to check
net/core/skbuff.c +20 -0
@@ -263,6 +263,26 @@ struct sk_buff *__netdev_alloc_skb(strucreturn skb; } +struct page *__netdev_alloc_page (struct net_device *dev,gfp_t gfp_mask) +{ +int node = dev->dev.parent ?dev_to_node (dev->dev.parent) :-1 ; +struct page *page; + + page =alloc_pages_node (node, gfp_mask,0 ); +return page; +} +EXPORT_SYMBOL (__netdev_alloc_page); + +void skb_add_rx_frag (struct sk_buff *skb,int i,struct page *page,int off, +int size) +{ +skb_fill_page_desc (skb, i, page, off, size); + skb->len += size; + skb->data_len += size; + skb->truesize += size; +} +EXPORT_SYMBOL (skb_add_rx_frag); +/** * dev_alloc_skb - allocate an skbuff for receiving * @length: length to allocate
drivers/net/sky2.c +6 -10
@@ -1343,7 +1343,7 @@ static struct sk_buff *sky2_rx_alloc(str }for (i =0 ; i < sky2->rx_nfrags; i++) { -struct page *page =alloc_page (GFP_ATOMIC ); +struct page *page =netdev_alloc_page (sky2->netdev);if (!page) goto free_partial;
@@ -2217,8 +2217,8 @@ static struct sk_buff *receive_copy(stru }/* Adjust length of skb with fragments to match received data */ -static void skb_put_frags (struct sk_buff *skb,unsigned int hdr_space, -unsigned int length) +static void skb_put_frags (struct sky2_port *sky2,struct sk_buff *skb, +unsigned int hdr_space,unsigned int length) {int i, num_frags;unsigned int size;
@@ -2235,15 +2235,11 @@ static void skb_put_frags(struct sk_buffif (length ==0 ) {/* don't need this page */ -__free_page (frag->page); +netdev_free_page (sky2->netdev, frag->page); --skb_shinfo (skb)->nr_frags; }else { size =min (length, (unsigned )PAGE_SIZE ); - - frag->size = size; - skb->data_len += size; - skb->truesize += size; - skb->len += size; +skb_add_rx_frag (skb, i, frag->page,0 , size); length -= size; } }
@@ -2270,7 +2266,7 @@ static struct sk_buff *receive_new(strucsky2_rx_map_skb (sky2->hw->pdev, re, hdr_space);if (skb_shinfo (skb)->nr_frags) -skb_put_frags (skb, hdr_space, length); +skb_put_frags (sky2, skb, hdr_space, length);else skb_put (skb, length);return skb;
drivers/net/bnx2.c +3 -5
@@ -2466,7 +2466,7 @@ bnx2_alloc_rx_page(struct bnx2 *bp, strustruct sw_pg *rx_pg = &rxr->rx_pg_ring[index];struct rx_bd *rxbd = &rxr->rx_pg_desc_ring[RX_RING (index)][RX_IDX (index)]; -struct page *page =alloc_page (GFP_ATOMIC ); +struct page *page =netdev_alloc_page (bp->dev);if (!page)return -ENOMEM ;
@@ -2491,7 +2491,7 @@ bnx2_free_rx_page(struct bnx2 *bp, strucpci_unmap_page (bp->pdev,pci_unmap_addr (rx_pg, mapping),PAGE_SIZE ,PCI_DMA_FROMDEVICE ); -__free_page (page); +netdev_free_page (bp->dev, page); rx_pg->page =NULL ; }
@@ -2816,9 +2816,7 @@ bnx2_rx_skb(struct bnx2 *bp, struct bnx2 } frag_size -= frag_len; - skb->data_len += frag_len; - skb->truesize += frag_len; - skb->len += frag_len; +skb_add_rx_frag (skb, i, rx_pg->page,0 , frag_len); pg_prod =NEXT_RX_BD (pg_prod); pg_cons =RX_PG_RING_IDX (NEXT_RX_BD (pg_cons));
drivers/net/e1000e/netdev.c +2 -5
@@ -257,7 +257,7 @@ static void e1000_alloc_rx_buffers_ps(stcontinue ; }if (!ps_page->page) { - ps_page->page =alloc_page (GFP_ATOMIC ); + ps_page->page =netdev_alloc_page (netdev);if (!ps_page->page) { adapter->alloc_rx_buff_failed++; goto no_buffers;
@@ -816,11 +816,8 @@ static bool e1000_clean_rx_irq_ps(structpci_unmap_page (pdev, ps_page->dma,PAGE_SIZE ,PCI_DMA_FROMDEVICE ); ps_page->dma =0 ; -skb_fill_page_desc (skb, j, ps_page->page,0 , length); +skb_add_rx_frag (skb, j, ps_page->page,0 , length); ps_page->page =NULL ; - skb->len += length; - skb->data_len += length; - skb->truesize += length; } copydone:
drivers/net/igb/igb_main.c +2 -6
@@ -3526,13 +3526,9 @@ static bool igb_clean_rx_irq_adv(structpci_unmap_page (pdev, buffer_info->page_dma,PAGE_SIZE ,PCI_DMA_FROMDEVICE ); buffer_info->page_dma =0 ; -skb_fill_page_desc (skb, j, buffer_info->page, -0 , length); +skb_add_rx_frag (skb, j, buffer_info->page,0 , length); buffer_info->page =NULL ; - skb->len += length; - skb->data_len += length; - skb->truesize += length; rx_desc->wb.upper.status_error =0 ;if (staterr &E1000_RXD_STAT_EOP )break ;
@@ -3634,7 +3630,7 @@ static void igb_alloc_rx_buffers_adv(str rx_desc =E1000_RX_DESC_ADV (*rx_ring, i);if (adapter->rx_ps_hdr_size && !buffer_info->page) { - buffer_info->page =alloc_page (GFP_ATOMIC ); + buffer_info->page =netdev_alloc_page (netdev);if (!buffer_info->page) { adapter->alloc_rx_buff_failed++; goto no_buffers;
drivers/net/ixgbe/ixgbe_main.c +3 -7
@@ -486,7 +486,7 @@ static void ixgbe_alloc_rx_buffers(strucif (!rx_buffer_info->page && (adapter->flags &IXGBE_FLAG_RX_PS_ENABLED )) { - rx_buffer_info->page =alloc_page (GFP_ATOMIC ); + rx_buffer_info->page =netdev_alloc_page (netdev);if (!rx_buffer_info->page) { adapter->alloc_rx_page_failed++; goto no_buffers;
@@ -607,13 +607,9 @@ static bool ixgbe_clean_rx_irq(struct ixpci_unmap_page (pdev, rx_buffer_info->page_dma,PAGE_SIZE ,PCI_DMA_FROMDEVICE ); rx_buffer_info->page_dma =0 ; -skb_fill_page_desc (skb,skb_shinfo (skb)->nr_frags, - rx_buffer_info->page,0 , upper_len); +skb_add_rx_frag (skb,skb_shinfo (skb)->nr_frags, + rx_buffer_info->page,0 , upper_len); rx_buffer_info->page =NULL ; - - skb->len += upper_len; - skb->data_len += upper_len; - skb->truesize += upper_len; } i++;
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 16/30 net: sk_allocation() - concentrate socket related allocations
In reply to Peter ZijlstraIntroduce sk_allocation(), this function allows to inject sock specific flags to each sock related allocation.
--- include/net/sock.h | 5 +++++ net/ipv4/tcp.c | 3 ++- net/ipv4/tcp_output.c | 12 +++++++----- net/ipv6/tcp_ipv6.c | 17 ++++++++++++----- 4 files changed, 26 insertions(+), 11 deletions(-)
net/ipv4/tcp_output.c +7 -5
@@ -2088,7 +2088,8 @@ void tcp_send_fin(struct sock *sk) }else {/* Socket is locked, keep trying until memory is available. */ for (;;) { - skb =alloc_skb_fclone (MAX_TCP_HEADER ,GFP_KERNEL ); + skb =alloc_skb_fclone (MAX_TCP_HEADER , +sk_allocation (sk,GFP_KERNEL ));if (skb)break ;yield ();
@@ -2114,7 +2115,7 @@ void tcp_send_active_reset(struct sock *struct sk_buff *skb;/* NOTE: No TCP options attached and we never retransmit this. */ - skb =alloc_skb (MAX_TCP_HEADER , priority); + skb =alloc_skb (MAX_TCP_HEADER ,sk_allocation (sk, priority));if (!skb) {NET_INC_STATS (LINUX_MIB_TCPABORTFAILED );return ;
@@ -2183,7 +2184,8 @@ struct sk_buff *tcp_make_synack(struct s__u8 *md5_hash_location;#endif - skb =sock_wmalloc (sk,MAX_TCP_HEADER +15 ,1 ,GFP_ATOMIC ); + skb =sock_wmalloc (sk,MAX_TCP_HEADER +15 ,1 , +sk_allocation (sk,GFP_ATOMIC ));if (skb ==NULL )return NULL ;
@@ -2441,7 +2443,7 @@ void tcp_send_ack(struct sock *sk)* tcp_transmit_skb() will set the ownership to this * sock. */ - buff =alloc_skb (MAX_TCP_HEADER ,GFP_ATOMIC ); + buff =alloc_skb (MAX_TCP_HEADER ,sk_allocation (sk,GFP_ATOMIC ));if (buff ==NULL ) {inet_csk_schedule_ack (sk);inet_csk (sk)->icsk_ack.ato =TCP_ATO_MIN ;
@@ -2476,7 +2478,7 @@ static int tcp_xmit_probe_skb(struct socstruct sk_buff *skb;/* We don't queue it, tcp_transmit_skb() sets ownership. */ - skb =alloc_skb (MAX_TCP_HEADER ,GFP_ATOMIC ); + skb =alloc_skb (MAX_TCP_HEADER ,sk_allocation (sk,GFP_ATOMIC ));if (skb ==NULL )return -1 ;
include/net/sock.h +5 -0
@@ -435,6 +435,11 @@ static inline int sock_flag(struct sockreturn test_bit (flag, &sk->sk_flags); } +static inline gfp_t sk_allocation (struct sock *sk,gfp_t gfp_mask) +{ +return gfp_mask; +} +static inline void sk_acceptq_removed (struct sock *sk) { sk->sk_ack_backlog--;
net/ipv6/tcp_ipv6.c +12 -5
@@ -580,7 +580,8 @@ static int tcp_v6_md5_do_add(struct sock }else {/* reallocate new list if current one is full. */ if (!tp->md5sig_info) { - tp->md5sig_info =kzalloc (sizeof (*tp->md5sig_info),GFP_ATOMIC ); + tp->md5sig_info =kzalloc (sizeof (*tp->md5sig_info), +sk_allocation (sk,GFP_ATOMIC ));if (!tp->md5sig_info) {kfree (newkey);return -ENOMEM ;
@@ -593,7 +594,8 @@ static int tcp_v6_md5_do_add(struct sock }if (tp->md5sig_info->alloced6 == tp->md5sig_info->entries6) { keys =kmalloc ((sizeof (tp->md5sig_info->keys6[0 ]) * - (tp->md5sig_info->entries6 +1 )),GFP_ATOMIC ); + (tp->md5sig_info->entries6 +1 )), +sk_allocation (sk,GFP_ATOMIC ));if (!keys) {tcp_free_md5sig_pool ();
@@ -717,7 +719,8 @@ static int tcp_v6_parse_md5_keys (structstruct tcp_sock *tp =tcp_sk (sk);struct tcp_md5sig_info *p; - p =kzalloc (sizeof (struct tcp_md5sig_info ),GFP_KERNEL ); + p =kzalloc (sizeof (struct tcp_md5sig_info ), +sk_allocation (sk,GFP_KERNEL ));if (!p)return -ENOMEM ;
@@ -920,6 +923,7 @@ static void tcp_v6_send_reset(struct soc#ifdef CONFIG_TCP_MD5SIG struct tcp_md5sig_key *key;#endif +gfp_t gfp_mask =GFP_ATOMIC ;if (th->rst)return ;
@@ -937,13 +941,16 @@ static void tcp_v6_send_reset(struct soc tot_len +=TCPOLEN_MD5SIG_ALIGNED ;#endif +if (sk) + gfp_mask =sk_allocation (skb->sk, gfp_mask); +/* * We need to grab some memory, and put together an RST, * and then put it into the queue to be sent. */ buff =alloc_skb (MAX_HEADER +sizeof (struct ipv6hdr ) + tot_len, -GFP_ATOMIC ); +sk_allocation (sk,GFP_ATOMIC ));if (buff ==NULL )return ;
@@ -1032,7 +1039,7 @@ static void tcp_v6_send_ack(struct sk_bu#endif buff =alloc_skb (MAX_HEADER +sizeof (struct ipv6hdr ) + tot_len, -GFP_ATOMIC ); + gfp_mask);if (buff ==NULL )return ;
net/ipv4/tcp.c +2 -1
@@ -637,7 +637,8 @@ struct sk_buff *sk_stream_alloc_skb(stru/* The TCP header must be at least 32-bit aligned. */ size =ALIGN (size,4 ); - skb =alloc_skb_fclone (size + sk->sk_prot->max_header, gfp); + skb =alloc_skb_fclone (size + sk->sk_prot->max_header, +sk_allocation (sk, gfp));if (skb) {if (sk_wmem_schedule (sk, skb->truesize)) {/*
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 17/30 netvm: network reserve infrastructure
In reply to Peter ZijlstraProvide the basic infrastructure to reserve and charge/account network memory.
We provide the following reserve tree:
1) total network reserve
2) network TX reserve
3) protocol TX pages
4) network RX reserve
5) SKB data reserve
[1] is used to make all the network reserves a single subtree, for easy manipulation.
[2] and [4] are merely for eastetic reasons.
The TX pages reserve [3] is assumed bounded by it being the upper bound of memory that can be used for sending pages (not quite true, but good enough)
The SKB reserve [5] is an aggregate reserve, which is used to charge SKB data against in the fallback path.
The consumers for these reserves are sockets marked with:
SOCK_MEMALLOC
Such sockets are to be used to service the VM (iow. to swap over). They must be handled kernel side, exposing such a socket to user-space is a BUG.
--- include/net/sock.h | 43 ++++++++++++++++++++- net/Kconfig | 3 + net/core/sock.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-)
include/net/sock.h +42 -1
@@ -51,6 +51,7 @@#include <linux/skbuff.h> /* struct sk_buff */ #include <linux/mm.h> #include <linux/security.h> +#include <linux/reserve.h> #include <linux/filter.h>
@@ -406,6 +407,7 @@ enum sock_flags {SOCK_RCVTSTAMPNS ,/* %SO_TIMESTAMPNS setting */ SOCK_LOCALROUTE ,/* route locally only, %SO_DONTROUTE setting */ SOCK_QUEUE_SHRUNK ,/* write queue has been shrunk recently */ + SOCK_MEMALLOC, /* the VM depends on us - make sure we're serviced */ };static inline void sock_copy_flags (struct sock *nsk,struct sock *osk)
@@ -428,9 +430,48 @@ static inline int sock_flag(struct sockreturn test_bit (flag, &sk->sk_flags); } +static inline int sk_has_memalloc (struct sock *sk) +{ +return sock_flag (sk,SOCK_MEMALLOC ); +} + +extern struct mem_reserve net_rx_reserve; +extern struct mem_reserve net_skb_reserve; + +#ifdef CONFIG_NETVM +/* +* Guestimate the per request queue TX upper bound. +* +* Max packet size is 64k, and we need to reserve that much since the data +* might need to bounce it. Double it to be on the safe side. +*/ +#define TX_RESERVE_PAGES DIV_ROUND_UP(2*65536, PAGE_SIZE) + +extern int memalloc_socks; + +static inline int sk_memalloc_socks (void ) +{ +return memalloc_socks; +} + +extern int sk_adjust_memalloc (int socks,long tx_reserve_pages); +extern int sk_set_memalloc (struct sock *sk); +extern int sk_clear_memalloc (struct sock *sk); +#else +static inline int sk_memalloc_socks (void ) +{ +return 0 ; +} + +static inline int sk_clear_memalloc (struct sock *sk) +{ +return 0 ; +} +#endif +static inline gfp_t sk_allocation (struct sock *sk,gfp_t gfp_mask) { -return gfp_mask; +return gfp_mask | (sk->sk_allocation & __GFP_MEMALLOC); }static inline void sk_acceptq_removed (struct sock *sk)
net/core/sock.c +107 -0
131 lines not on this page · raw message
net/Kconfig +3 -0
@@ -250,6 +250,9 @@ endmenu source "net/rfkill/Kconfig" source "net/9p/Kconfig" +config NETVM + def_bool n + endif # if NET endmenu # Networking
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 18/30 netvm: INET reserves.
In reply to Peter ZijlstraAdd reserves for INET.
The two big users seem to be the route cache and ip-fragment cache.
Reserve the route cache under generic RX reserve, its usage is bounded by the high reclaim watermark, and thus does not need further accounting.
Reserve the ip-fragement caches under SKB data reserve, these add to the SKB RX limit. By ensuring we can at least receive as much data as fits in the reassmbly line we avoid fragment attack deadlocks.
Adds to the reserve tree:
total network reserve
network TX reserve
protocol TX pages
network RX reserve
+ IPv6 route cache
+ IPv4 route cache
SKB data reserve
+ IPv6 fragment cache
+ IPv4 fragment cache
--- include/net/inet_frag.h | 7 +++ include/net/netns/ipv6.h | 4 ++ net/ipv4/inet_fragment.c | 3 + net/ipv4/ip_fragment.c | 89 +++++++++++++++++++++++++++++++++++++++++++++-- net/ipv4/route.c | 72 +++++++++++++++++++++++++++++++++++++- net/ipv6/af_inet6.c | 20 +++++++++- net/ipv6/reassembly.c | 88 +++++++++++++++++++++++++++++++++++++++++++++- net/ipv6/route.c | 66 ++++++++++++++++++++++++++++++++++ 8 files changed, 341 insertions(+), 8 deletions(-)
net/ipv4/ip_fragment.c +87 -2
@@ -42,6 +42,8 @@#include <linux/udp.h> #include <linux/inet.h> #include <linux/netfilter_ipv4.h> +#include <linux/reserve.h> +#include <linux/nsproxy.h> /* NOTE. Logic of IP defragmentation is parallel to corresponding IPv6 * code now. If you change something here, _PLEASE_ update ipv6/reassembly.c
@@ -596,6 +598,66 @@ int ip_defrag(struct sk_buff *skb, u32 u }#ifdef CONFIG_SYSCTL +static int proc_dointvec_fragment (struct ctl_table *table,int write, +struct file *filp,void __user *buffer,size_t *lenp, +loff_t *ppos) +{ +struct net *net = current->nsproxy->net_ns; +int new_bytes, ret; + +mutex_lock (&net->ipv4.frags.lock); + +if (write) + table->data = &new_bytes; + + ret =proc_dointvec (table, write, filp, buffer, lenp, ppos); + +if (!ret && write) { + ret =mem_reserve_kmalloc_set (&net->ipv4.frags.reserve, + new_bytes); +if (!ret) + net->ipv4.frags.high_thresh = new_bytes; + } + +if (write) + table->data = &net->ipv4.frags.high_thresh; + +mutex_unlock (&net->ipv4.frags.lock); + +return ret; +} + +static int sysctl_intvec_fragment (struct ctl_table *table, +int __user *name,int nlen, +void __user *oldval,size_t __user *oldlenp, +void __user *newval,size_t newlen) +{ +struct net *net = current->nsproxy->net_ns; +int write = (newval && newlen); +int new_bytes, ret; + +mutex_lock (&net->ipv4.frags.lock); + +if (write) + table->data = &new_bytes; + + ret =sysctl_intvec (table, name, nlen, oldval, oldlenp, newval, newlen); + +if (!ret && write) { + ret =mem_reserve_kmalloc_set (&net->ipv4.frags.reserve, + new_bytes); +if (!ret) + net->ipv4.frags.high_thresh = new_bytes; + } + +if (write) + table->data = &net->ipv4.frags.high_thresh; + +mutex_unlock (&net->ipv4.frags.lock); + +return ret; +} +static int zero; static struct ctl_table ip4_frags_ns_ctl_table[] = {
@@ -605,7 +667,8 @@ static struct ctl_table ip4_frags_ns_ctl .data = &init_net.ipv4.frags.high_thresh, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = &proc_dointvec + .proc_handler = &proc_dointvec_fragment, + .strategy = &sysctl_intvec_fragment, }, { .ctl_name = NET_IPV4_IPFRAG_LOW_THRESH,
@@ -708,6 +771,8 @@ static inline void ip4_frags_ctl_registestatic int ipv4_frags_init_net (struct net *net) { +int ret; +/* * Fragment cache limits. We will commit 256K at one time. Should we * cross that limit we will prune down to 192K. This should cope with
@@ -725,11 +790,31 @@ static int ipv4_frags_init_net(struct neinet_frags_init_net (&net->ipv4.frags); -return ip4_frags_ns_ctl_register (net); + ret =ip4_frags_ns_ctl_register (net); +if (ret) + goto out_reg; + +mem_reserve_init (&net->ipv4.frags.reserve,"IPv4 fragment cache" , + &net_skb_reserve); + ret =mem_reserve_kmalloc_set (&net->ipv4.frags.reserve, + net->ipv4.frags.high_thresh); +if (ret) + goto out_reserve; + +return 0 ; + +out_reserve: +mem_reserve_disconnect (&net->ipv4.frags.reserve); +ip4_frags_ns_ctl_unregister (net); +out_reg: +inet_frags_exit_net (&net->ipv4.frags, &ip4_frags); + +return ret; }static void ipv4_frags_exit_net (struct net *net) { +mem_reserve_disconnect (&net->ipv4.frags.reserve);ip4_frags_ns_ctl_unregister (net);inet_frags_exit_net (&net->ipv4.frags, &ip4_frags); }
net/ipv6/reassembly.c +86 -2
122 lines not on this page · raw message
net/ipv4/route.c +71 -1
103 lines not on this page · raw message
net/ipv6/route.c +65 -1
90 lines not on this page · raw message
include/net/inet_frag.h +7 -0
@@ -1,6 +1,9 @@ #ifndef __NET_FRAG_H__ #define __NET_FRAG_H__ +#include <linux/reserve.h> +#include <linux/mutex.h> + struct netns_frags { int nqueues; atomic_t mem;
@@ -10,6 +13,10 @@ struct netns_frags {int timeout;int high_thresh;int low_thresh; + +/* reserves */ +struct mutex lock; +struct mem_reserve reserve; };struct inet_frag_queue {
net/ipv4/inet_fragment.c +3 -0
@@ -19,6 +19,7 @@#include <linux/random.h> #include <linux/skbuff.h> #include <linux/rtnetlink.h> +#include <linux/reserve.h> #include <net/inet_frag.h>
@@ -74,6 +75,8 @@ void inet_frags_init_net(struct netns_fr nf->nqueues =0 ;atomic_set (&nf->mem,0 );INIT_LIST_HEAD (&nf->lru_list); +mutex_init (&nf->lock); +mem_reserve_init (&nf->reserve,"IP fragement cache" ,NULL ); }EXPORT_SYMBOL (inet_frags_init_net);
include/net/netns/ipv6.h +4 -0
@@ -24,6 +24,8 @@ struct netns_sysctl_ipv6 {int ip6_rt_mtu_expires;int ip6_rt_min_advmss;int icmpv6_time; + +struct mutex ip6_rt_lock; };struct netns_ipv6 {
@@ -55,5 +57,7 @@ struct netns_ipv6 {struct sock *ndisc_sk;struct sock *tcp_sk;struct sock *igmp_sk; + + struct mem_reserve ip6_rt_reserve; };#endif
net/ipv6/af_inet6.c +18 -2
@@ -851,6 +851,20 @@ static int inet6_net_init(struct net *ne net->ipv6.sysctl.ip6_rt_min_advmss =IPV6_MIN_MTU -20 -40 ; net->ipv6.sysctl.icmpv6_time =1 *HZ ; +mem_reserve_init (&net->ipv6.ip6_rt_reserve,"IPv6 route cache" , + &net_rx_reserve); +/* +* XXX: requires that net->ipv6.ip6_dst_ops is already set-up +* but afaikt its impossible to order the various +* pernet_subsys calls so that this one is done after +* ip6_route_net_init(). +*/ + err =mem_reserve_kmem_cache_set (&net->ipv6.ip6_rt_reserve, + net->ipv6.ip6_dst_ops.kmem_cachep, + net->ipv6.sysctl.ip6_rt_max_size); +if (err) + goto reserve_fail; +#ifdef CONFIG_PROC_FS err =udp6_proc_init (net);if (err)
@@ -861,8 +875,8 @@ static int inet6_net_init(struct net *ne err =ac6_proc_init (net);if (err) goto proc_ac6_fail; -out:#endif +out:return err;#ifdef CONFIG_PROC_FS
@@ -870,8 +884,10 @@ proc_ac6_fail:tcp6_proc_exit (net); proc_tcp6_fail:udp6_proc_exit (net); - goto out;#endif +reserve_fail: +mem_reserve_disconnect (&net->ipv6.ip6_rt_reserve); + goto out; }static void inet6_net_exit (struct net *net)
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 18/30] netvm: INET reserves.
Quoted 24 lines
Add reserves for INET.
The two big users seem to be the route cache and ip-fragment cache.
Reserve the route cache under generic RX reserve, its usage is bounded by the high reclaim watermark, and thus does not need further accounting.
Reserve the ip-fragement caches under SKB data reserve, these add to the SKB RX limit. By ensuring we can at least receive as much data as fits in the reassmbly line we avoid fragment attack deadlocks.
Adds to the reserve tree:
total network reserve
network TX reserve
protocol TX pages
network RX reserve(quoted diff) +4
-0+ IPv6 route cache + IPv4 route cache SKB data reserve + IPv6 fragment cache + IPv4 fragment cacheSigned-off-by Peter Zijlstra <[email protected]>
Quoted 11 lines
--- include/net/inet_frag.h | 7 +++ include/net/netns/ipv6.h | 4 ++ net/ipv4/inet_fragment.c | 3 + net/ipv4/ip_fragment.c | 89 +++++++++++++++++++++++++++++++++++++++++++++-- net/ipv4/route.c | 72 +++++++++++++++++++++++++++++++++++++- net/ipv6/af_inet6.c | 20 +++++++++- net/ipv6/reassembly.c | 88 +++++++++++++++++++++++++++++++++++++++++++++- net/ipv6/route.c | 66 ++++++++++++++++++++++++++++++++++ 8 files changed, 341 insertions(+), 8 deletions(-)
Sorry for the delay ...
[ cut ]
I removed a big portion of code because the remarks below apply to the rest of the code.
net/ipv6/route.c int ipv6_sysctl_rtcache_flush(ctl_table · line 2536
Quoted 6 lines
net/ipv6/route.c +6
-0+static int sysctl_intvec_route (struct ctl_table *table, +int __user *name,int nlen, +void __user *oldval,size_t __user *oldlenp, +void __user *newval,size_t newlen) +{ +struct net *net = current->nsproxy->net_ns;
I think you can use the container_of and get rid of using current->nsproxy->net_ns.
struct net *net = container_of(table->data, struct net, ipv6.sysctl.ip6_rt_max_size);
Another solution could be to pass directly the sysctl structure pointer in the table data instead of
".data = &init_net.ipv6.sysctl.ip6_rt_max_size" when initializing the sysctl table below. But you have to set the right field value yourself.
Quoted 14 lines
net/ipv6/route.c +14
-0+int write = (newval && newlen); +int new_size, ret; + +mutex_lock (&net->ipv6.sysctl.ip6_rt_lock); + +if (write) + table->data = &new_size; + + ret =sysctl_intvec (table, name, nlen, oldval, oldlenp, newval, newlen); + +if (!ret && write) { + ret =mem_reserve_kmem_cache_set (&net->ipv6.ip6_rt_reserve, + net->ipv6.ip6_dst_ops.kmem_cachep, new_size); +if (!ret)
net/ipv6/route.c int ipv6_sysctl_rtcache_flush(ctl_table · line 2560
Quoted 10 lines
net/ipv6/route.c +10
-0+ net->ipv6.sysctl.ip6_rt_max_size = new_size; + } + +if (write) + table->data = &net->ipv6.sysctl.ip6_rt_max_size; + +mutex_unlock (&net->ipv6.sysctl.ip6_rt_lock); + +return ret; +}
Dancing with the table->data looks safe but it is not very nice.
Isn't possible to use a temporary table like in the function "ipv4_sysctl_local_port_range" ?
Quoted 95 lines
ctl_tableipv6_route_table_template[] = {net/ipv6/route.c +4
-1{ .procname = "flush",@@ -2520,7 +2581,8 @@ ctl_table ipv6_route_table_template[] = .data = &init_net.ipv6.sysctl.ip6_rt_max_size, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = &proc_dointvec, + .proc_handler = &proc_dointvec_route, + .strategy = &sysctl_intvec_route, }, { .ctl_name = NET_IPV6_ROUTE_GC_MIN_INTERVAL,@@ -2608,6 +2670,8 @@ struct ctl_table *ipv6_route_sysctl_init table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss; } +mutex_init (&net->ipv6.sysctl.ip6_rt_lock); +return table; }#endif Index:
linux-2.6/include/net/inet_frag.h
===================================================================include/net/inet_frag.h +7
-0@@ -1,6 +1,9 @@ #ifndef __NET_FRAG_H__ #define __NET_FRAG_H__ +#include <linux/reserve.h> +#include <linux/mutex.h> + struct netns_frags { int nqueues; atomic_t mem;@@ -10,6 +13,10 @@ struct netns_frags {int timeout;int high_thresh;int low_thresh; + +/* reserves */ +struct mutex lock; +struct mem_reserve reserve; };struct inet_frag_queue {Index:
linux-2.6/net/ipv4/inet_fragment.c
===================================================================net/ipv4/inet_fragment.c +3
-0@@ -19,6 +19,7 @@#include <linux/random.h> #include <linux/skbuff.h> #include <linux/rtnetlink.h> +#include <linux/reserve.h> #include <net/inet_frag.h> @@ -74,6 +75,8 @@ void inet_frags_init_net(struct netns_fr nf->nqueues =0 ;atomic_set (&nf->mem,0 );INIT_LIST_HEAD (&nf->lru_list); +mutex_init (&nf->lock); +mem_reserve_init (&nf->reserve,"IP fragement cache" ,NULL ); }EXPORT_SYMBOL (inet_frags_init_net);Index:
linux-2.6/include/net/netns/ipv6.h
===================================================================include/net/netns/ipv6.h +4
-0@@ -24,6 +24,8 @@ struct netns_sysctl_ipv6 {int ip6_rt_mtu_expires;int ip6_rt_min_advmss;int icmpv6_time; + +struct mutex ip6_rt_lock; };struct netns_ipv6 {@@ -55,5 +57,7 @@ struct netns_ipv6 {struct sock *ndisc_sk;struct sock *tcp_sk;struct sock *igmp_sk; + + struct mem_reserve ip6_rt_reserve; };#endif Index:
linux-2.6/net/ipv6/af_inet6.c
===================================================================net/ipv6/af_inet6.c +0
-0@@ -851,6 +851,20 @@ static int inet6_net_init(struct net *ne net->ipv6.sysctl.ip6_rt_min_advmss =IPV6_MIN_MTU -20 -40 ;
net/ipv6/af_inet6.c static int inet6_net_init(struct net *ne · line 861
Quoted 10 lines
net/ipv6/af_inet6.c +8
-0net->ipv6.sysctl.icmpv6_time =1 *HZ ; +mem_reserve_init (&net->ipv6.ip6_rt_reserve,"IPv6 route cache" , + &net_rx_reserve); +/* +* XXX: requires that net->ipv6.ip6_dst_ops is already set-up +* but afaikt its impossible to order the various +* pernet_subsys calls so that this one is done after +* ip6_route_net_init(). +*/
As this code seems related to the routes, is there a particular reason to not put it at the end of "ip6_route_net_init" function ? You will be sure "net->ipv6.ip6_dst_ops is already set-up", no ?
Quoted 20 lines
net/ipv6/af_inet6.c +7
-1+ err =mem_reserve_kmem_cache_set (&net->ipv6.ip6_rt_reserve, + net->ipv6.ip6_dst_ops.kmem_cachep, + net->ipv6.sysctl.ip6_rt_max_size); +if (err) + goto reserve_fail; +#ifdef CONFIG_PROC_FS err =udp6_proc_init (net);if (err)@@ -861,8 +875,8 @@ static int inet6_net_init(struct net *ne err =ac6_proc_init (net);if (err) goto proc_ac6_fail; -out:#endif +out:return err;#ifdef CONFIG_PROC_FS
net/ipv6/af_inet6.c proc_ac6_fail: · line 889
Quoted 7 lines
net/ipv6/af_inet6.c +2
-1@@ -870,8 +884,10 @@ proc_ac6_fail:tcp6_proc_exit (net); proc_tcp6_fail:udp6_proc_exit (net); - goto out;#endif +reserve_fail: +mem_reserve_disconnect (&net->ipv6.ip6_rt_reserve);
Idem.
net/ipv6/af_inet6.c proc_ac6_fail: · line 893
Quoted 4 lines
net/ipv6/af_inet6.c +1
-0+ goto out; }static void inet6_net_exit (struct net *net)
Isn't "mem_reserve_disconnect" missing here ? (but going to ip6_route_net_exit)
I hope this review helped :)
Thanks
--Daniel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 18/30] netvm: INET reserves.
Quoted 13 lines · Daniel Lezcano
I removed a big portion of code because the remarks below apply to the rest of the code.
net/ipv6/route.c int ipv6_sysctl_rtcache_flush(ctl_table · line 2536
Quoted 6 lines
net/ipv6/route.c +6
-0+static int sysctl_intvec_route (struct ctl_table *table, +int __user *name,int nlen, +void __user *oldval,size_t __user *oldlenp, +void __user *newval,size_t newlen) +{ +struct net *net = current->nsproxy->net_ns;I think you can use the
container_ofand get rid of usingcurrent->nsproxy->net_ns.
Quoted 2 lines
struct net *net = container_of(table->data, struct net, ipv6.sysctl.ip6_rt_max_size);
D'oh - why didn't I think of that... yes very nice.
Quoted 20 lines
Quoted 20 lines
net/ipv6/route.c +20
-0+int write = (newval && newlen); +int new_size, ret; + +mutex_lock (&net->ipv6.sysctl.ip6_rt_lock); + +if (write) + table->data = &new_size; + + ret =sysctl_intvec (table, name, nlen, oldval, oldlenp, newval, newlen); + +if (!ret && write) { + ret =mem_reserve_kmem_cache_set (&net->ipv6.ip6_rt_reserve, + net->ipv6.ip6_dst_ops.kmem_cachep, new_size); +if (!ret) + net->ipv6.sysctl.ip6_rt_max_size = new_size; + } + +if (write) + table->data = &net->ipv6.sysctl.ip6_rt_max_size; +
Quoted 8 lines
net/ipv6/route.c int ipv6_sysctl_rtcache_flush(ctl_table · line 2529
Quoted 4 lines
net/ipv6/route.c +4
-0+mutex_unlock (&net->ipv6.sysctl.ip6_rt_lock); + +return ret; +}Dancing with the
table->datalooks safe but it is not very nice. Isn't possible to use a temporary table like in the function "ipv4_sysctl_local_port_range" ?
Ah, nice solution. Thanks!
Quoted 8 lines
Quoted 8 lines
Index:
linux-2.6/net/ipv6/af_inet6.c
===================================================================net/ipv6/af_inet6.c +0
-0@@ -851,6 +851,20 @@ static int inet6_net_init(struct net *ne net->ipv6.sysctl.ip6_rt_min_advmss =IPV6_MIN_MTU -20 -40 ; net->ipv6.sysctl.icmpv6_time =1 *HZ ;
Quoted 12 lines
net/ipv6/af_inet6.c static int inet6_net_init(struct net *ne · line 861
Quoted 8 lines
net/ipv6/af_inet6.c +8
-0+mem_reserve_init (&net->ipv6.ip6_rt_reserve,"IPv6 route cache" , + &net_rx_reserve); +/* +* XXX: requires that net->ipv6.ip6_dst_ops is already set-up +* but afaikt its impossible to order the various +* pernet_subsys calls so that this one is done after +* ip6_route_net_init(). +*/ As this code seems related to the routes, is there a particular reason to not put it at the end of "
ip6_route_net_init" function ? You will be sure "net->ipv6.ip6_dst_opsis already set-up", no ?
Ah, the problem is that I need both dst_ops and ip6_rt_max_size set.
The former is set in ip6_route_net_init() while the later is set in inet6_net_init(), both are registered pernet_ops without specified order.
So where exactly do I hook in?
Quoted 30 lines
Quoted 20 lines
net/ipv6/af_inet6.c +7
-1+ err =mem_reserve_kmem_cache_set (&net->ipv6.ip6_rt_reserve, + net->ipv6.ip6_dst_ops.kmem_cachep, + net->ipv6.sysctl.ip6_rt_max_size); +if (err) + goto reserve_fail; +#ifdef CONFIG_PROC_FS err =udp6_proc_init (net);if (err)@@ -861,8 +875,8 @@ static int inet6_net_init(struct net *ne err =ac6_proc_init (net);if (err) goto proc_ac6_fail; -out:#endif +out:return err;#ifdef CONFIG_PROC_FS net/ipv6/af_inet6.c proc_ac6_fail: · line 889
Quoted 7 lines
net/ipv6/af_inet6.c +2
-1@@ -870,8 +884,10 @@ proc_ac6_fail:tcp6_proc_exit (net); proc_tcp6_fail:udp6_proc_exit (net); - goto out;#endif +reserve_fail: +mem_reserve_disconnect (&net->ipv6.ip6_rt_reserve);Idem.
Quoted 7 lines
net/ipv6/af_inet6.c proc_ac6_fail: · line 893
Quoted 4 lines
net/ipv6/af_inet6.c +1
-0+ goto out; }static void inet6_net_exit (struct net *net)Isn't "
mem_reserve_disconnect" missing here ? (but going toip6_route_net_exit)
Probably, I'll go over the exit paths once I get the init path ;-)
Quoted 1 line
I hope this review helped :)
It did, much appreciated!
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 19/30 netvm: hook skb allocation to reserves
In reply to Peter ZijlstraChange the skb allocation api to indicate RX usage and use this to fall back to the reserve when needed. SKBs allocated from the reserve are tagged in skb->emergency.
Teach all other skb ops about emergency skbs and the reserve accounting.
Use the (new) packet split API to allocate and track fragment pages from the emergency reserve. Do this using an atomic counter in page->index. This is needed because the fragments have a different sharing semantic than that indicated by skb_shinfo()->dataref.
Note that the decision to distinguish between regular and emergency SKBs allows the accounting overhead to be limited to the later kind.
--- include/linux/mm_types.h | 1 include/linux/skbuff.h | 25 +++++++-- net/core/skbuff.c | 129 +++++++++++++++++++++++++++++++++++++---------- 3 files changed, 124 insertions(+), 31 deletions(-)
include/linux/skbuff.h +20 -5
@@ -317,7 +317,8 @@ struct sk_buff {#ifdef CONFIG_IPV6_NDISC_NODETYPE __u8 ndisc_nodetype:2;#endif -/* 14 bit hole */ + __u8 emergency:1; +/* 13 bit hole */ #ifdef CONFIG_NET_DMA dma_cookie_t dma_cookie;
@@ -348,10 +349,22 @@ struct sk_buff {#include <asm/system.h> +#define SKB_ALLOC_FCLONE 0x01 +#define SKB_ALLOC_RX 0x02 + +static inline bool skb_emergency (const struct sk_buff *skb) +{ +#ifdef CONFIG_NETVM +return unlikely (skb->emergency); +#else +return false; +#endif +} +extern void kfree_skb (struct sk_buff *skb);extern void __kfree_skb (struct sk_buff *skb);extern struct sk_buff *__alloc_skb (unsigned int size, -gfp_t priority,int fclone,int node); +gfp_t priority,int flags,int node);static inline struct sk_buff *alloc_skb (unsigned int size,gfp_t priority) {
@@ -361,7 +374,7 @@ static inline struct sk_buff *alloc_skb(static inline struct sk_buff *alloc_skb_fclone (unsigned int size,gfp_t priority) { -return __alloc_skb (size, priority,1 ,-1 ); +return __alloc_skb (size, priority,SKB_ALLOC_FCLONE ,-1 ); }extern struct sk_buff *skb_morph (struct sk_buff *dst,struct sk_buff *src);
@@ -1211,7 +1224,8 @@ static inline void __skb_queue_purge(strstatic inline struct sk_buff *__dev_alloc_skb (unsigned int length,gfp_t gfp_mask) { -struct sk_buff *skb =alloc_skb (length +NET_SKB_PAD , gfp_mask); +struct sk_buff *skb = +__alloc_skb (length +NET_SKB_PAD , gfp_mask,SKB_ALLOC_RX ,-1 );if (likely (skb))skb_reserve (skb,NET_SKB_PAD );return skb;
@@ -1242,6 +1256,7 @@ static inline struct sk_buff *netdev_all }extern struct page *__netdev_alloc_page (struct net_device *dev,gfp_t gfp_mask); +extern void __netdev_free_page (struct net_device *dev,struct page *page);/** * netdev_alloc_page - allocate a page for ps-rx on a specific device
@@ -1258,7 +1273,7 @@ static inline struct page *netdev_alloc_static inline void netdev_free_page (struct net_device *dev,struct page *page) { -__free_page (page); +__netdev_free_page (dev, page); }/**
net/core/skbuff.c +103 -26
306 lines not on this page · raw message
include/linux/mm_types.h +1 -0
@@ -74,6 +74,7 @@ struct page {pgoff_t index;/* Our offset within mapping. */ void *freelist;/* SLUB: freelist req. slab lock */ int reserve;/* page_alloc: page is a reserve page */ +atomic_t frag_count;/* skb fragment use count */ };struct list_head lru;/* Pageout list, eg. active_list * protected by zone->lru_lock !
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 20/30 netvm: filter emergency skbs.
In reply to Peter ZijlstraToss all emergency packets not for a SOCK_MEMALLOC socket. This ensures our precious memory reserve doesn't get stuck waiting for user-space.
The correctness of this approach relies on the fact that networks must be assumed lossy.
--- net/core/filter.c | 3 +++ 1 file changed, 3 insertions(+)
net/core/filter.c +3 -0
@@ -81,6 +81,9 @@ int sk_filter(struct sock *sk, struct skint err;struct sk_filter *filter; +if (skb_emergency (skb) && !sk_has_memalloc (sk)) +return -ENOMEM ; + err =security_sock_rcv_skb (sk, skb);if (err)return err;
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 21/30 netvm: prevent a stream specific deadlock
In reply to Peter ZijlstraIt could happen that all !SOCK_MEMALLOC sockets have buffered so much data that we're over the global rmem limit. This will prevent SOCK_MEMALLOC buffers from receiving data, which will prevent userspace from running, which is needed to reduce the buffered data.
Fix this by exempting the SOCK_MEMALLOC sockets from the rmem limit.
--- include/net/sock.h | 7 ++++--- net/core/sock.c | 2 +- net/ipv4/tcp_input.c | 12 ++++++------ net/sctp/ulpevent.c | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-)
include/net/sock.h +4 -3
@@ -788,12 +788,13 @@ static inline int sk_wmem_schedule(struc__sk_mem_schedule (sk, size,SK_MEM_SEND ); } -static inline int sk_rmem_schedule (struct sock *sk,int size) +static inline int sk_rmem_schedule (struct sock *sk,struct sk_buff *skb) {if (!sk_has_account (sk))return 1 ; -return size <= sk->sk_forward_alloc || -__sk_mem_schedule (sk, size,SK_MEM_RECV ); +return skb->truesize <= sk->sk_forward_alloc || +__sk_mem_schedule (sk, skb->truesize,SK_MEM_RECV ) || +skb_emergency (skb); }static inline void sk_mem_reclaim (struct sock *sk)
net/core/sock.c +1 -1
@@ -383,7 +383,7 @@ int sock_queue_rcv_skb(struct sock *sk,if (err) goto out; -if (!sk_rmem_schedule (sk, skb->truesize)) { +if (!sk_rmem_schedule (sk, skb)) { err = -ENOBUFS ; goto out; }
net/ipv4/tcp_input.c +6 -6
@@ -3877,19 +3877,19 @@ static void tcp_ofo_queue(struct sock *sstatic int tcp_prune_ofo_queue (struct sock *sk);static int tcp_prune_queue (struct sock *sk); -static inline int tcp_try_rmem_schedule (struct sock *sk,unsigned int size) +static inline int tcp_try_rmem_schedule (struct sock *sk,struct sk_buff *skb) {if (atomic_read (&sk->sk_rmem_alloc) > sk->sk_rcvbuf || - !sk_rmem_schedule (sk, size)) { + !sk_rmem_schedule (sk, skb)) {if (tcp_prune_queue (sk) <0 )return -1 ; -if (!sk_rmem_schedule (sk, size)) { +if (!sk_rmem_schedule (sk, skb)) {if (!tcp_prune_ofo_queue (sk))return -1 ; -if (!sk_rmem_schedule (sk, size)) +if (!sk_rmem_schedule (sk, skb))return -1 ; } }
@@ -3945,7 +3945,7 @@ static void tcp_data_queue(struct sock *if (eaten <=0 ) { queue_and_out:if (eaten <0 && -tcp_try_rmem_schedule (sk, skb->truesize)) +tcp_try_rmem_schedule (sk, skb)) goto drop;skb_set_owner_r (skb, sk);
@@ -4016,7 +4016,7 @@ drop:TCP_ECN_check_ce (tp, skb); -if (tcp_try_rmem_schedule (sk, skb->truesize)) +if (tcp_try_rmem_schedule (sk, skb)) goto drop;/* Disable header prediction. */
net/sctp/ulpevent.c +1 -1
@@ -701,7 +701,7 @@ struct sctp_ulpevent *sctp_ulpevent_makeif (rx_count >= asoc->base.sk->sk_rcvbuf) {if ((asoc->base.sk->sk_userlocks &SOCK_RCVBUF_LOCK ) || - (!sk_rmem_schedule (asoc->base.sk, chunk->skb->truesize))) + (!sk_rmem_schedule (asoc->base.sk, chunk->skb))) goto fail; }
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 22/30 netfilter: NF_QUEUE vs emergency skbs
In reply to Peter ZijlstraAvoid memory getting stuck waiting for userspace, drop all emergency packets. This of course requires the regular storage route to not include an NF_QUEUE target ;-)
--- net/netfilter/core.c | 3 +++ 1 file changed, 3 insertions(+)
net/netfilter/core.c +3 -0
@@ -176,9 +176,12 @@ next_hook: ret =1 ; goto unlock; }else if (verdict ==NF_DROP ) { +drop:kfree_skb (skb); ret = -EPERM ; }else if ((verdict &NF_VERDICT_MASK ) ==NF_QUEUE ) { +if (skb_emergency (*pskb)) + goto drop;if (!nf_queue (skb, elem, pf, hook, indev, outdev, okfn, verdict >>NF_VERDICT_BITS )) goto next_hook;
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 23/30 netvm: skb processing
In reply to Peter ZijlstraIn order to make sure emergency packets receive all memory needed to proceed ensure processing of emergency SKBs happens under PF_MEMALLOC.
Use the (new) sk_backlog_rcv() wrapper to ensure this for backlog processing.
Skip taps, since those are user-space again.
--- include/net/sock.h | 5 ++++ net/core/dev.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++------ net/core/sock.c | 16 ++++++++++++++ 3 files changed, 74 insertions(+), 6 deletions(-)
net/core/dev.c +53 -6
@@ -2008,6 +2008,30 @@ out: }#endif +/* +* Filter the protocols for which the reserves are adequate. +* +* Before adding a protocol make sure that it is either covered by the existing +* reserves, or add reserves covering the memory need of the new protocol's +* packet processing. +*/ +static int skb_emergency_protocol (struct sk_buff *skb) +{ +if (skb_emergency (skb)) +switch (skb->protocol) { +case __constant_htons (ETH_P_ARP ): +case __constant_htons (ETH_P_IP ): +case __constant_htons (ETH_P_IPV6 ): +case __constant_htons (ETH_P_8021Q ): +break ; + +default : +return 0 ; + } + +return 1 ; +} +/** * netif_receive_skb - process receive buffer from network * @skb: buffer to process
@@ -2029,10 +2053,23 @@ int netif_receive_skb(struct sk_buff *skstruct net_device *orig_dev;int ret =NET_RX_DROP ;__be16 type; +unsigned long pflags = current->flags; + +/* Emergency skb are special, they should +* - be delivered to SOCK_MEMALLOC sockets only +* - stay away from userspace +* - have bounded memory usage +* +* Use PF_MEMALLOC as a poor mans memory pool - the grouping kind. +* This saves us from propagating the allocation context down to all +* allocation sites. +*/ +if (skb_emergency (skb)) + current->flags |=PF_MEMALLOC ;/* if we've gotten here through NAPI, check netpoll */ if (netpoll_receive_skb (skb)) -return NET_RX_DROP ; + goto out;if (!skb->tstamp.tv64)net_timestamp (skb);
@@ -2043,7 +2080,7 @@ int netif_receive_skb(struct sk_buff *sk orig_dev =skb_bond (skb);if (!orig_dev) -return NET_RX_DROP ; + goto out;__get_cpu_var (netdev_rx_stat).total++;
@@ -2062,6 +2099,9 @@ int netif_receive_skb(struct sk_buff *sk }#endif +if (skb_emergency (skb)) + goto skip_taps; +list_for_each_entry_rcu (ptype, &ptype_all, list) {if (!ptype->dev || ptype->dev == skb->dev) {if (pt_prev)
@@ -2070,19 +2110,23 @@ int netif_receive_skb(struct sk_buff *sk } } +skip_taps: #ifdef CONFIG_NET_CLS_ACT skb =handle_ing (skb, &pt_prev, &ret, orig_dev);if (!skb) - goto out; + goto unlock; ncls: #endif +if (!skb_emergency_protocol (skb)) + goto drop; + skb =handle_bridge (skb, &pt_prev, &ret, orig_dev);if (!skb) - goto out; + goto unlock; skb =handle_macvlan (skb, &pt_prev, &ret, orig_dev);if (!skb) - goto out; + goto unlock; type = skb->protocol; list_for_each_entry_rcu(ptype,
@@ -2098,6 +2142,7 @@ ncls:if (pt_prev) { ret = pt_prev->func (skb, skb->dev, pt_prev, orig_dev); }else { +drop:kfree_skb (skb);/* Jamal, now you will not able to escape explaining * me how you were going to use this. :-)
@@ -2105,8 +2150,10 @@ ncls: ret =NET_RX_DROP ; } -out: +unlock:rcu_read_unlock (); +out: +tsk_restore_flags (current, pflags,PF_MEMALLOC );return ret; }
include/net/sock.h +5 -0
@@ -521,8 +521,13 @@ static inline void sk_add_backlog(struct skb->next =NULL ; } +extern int __sk_backlog_rcv (struct sock *sk,struct sk_buff *skb); +static inline int sk_backlog_rcv (struct sock *sk,struct sk_buff *skb) { +if (skb_emergency (skb)) +return __sk_backlog_rcv (sk, skb); +return sk->sk_backlog_rcv (sk, skb); }
net/core/sock.c +16 -0
@@ -313,6 +313,22 @@ int sk_clear_memalloc(struct sock *sk) return set; }EXPORT_SYMBOL_GPL (sk_clear_memalloc); + +int __sk_backlog_rcv (struct sock *sk,struct sk_buff *skb) +{ +int ret; +unsigned long pflags = current->flags; + +/* these should have been dropped before queueing */ +BUG_ON (!sk_has_memalloc (sk)); + + current->flags |=PF_MEMALLOC ; + ret = sk->sk_backlog_rcv (sk, skb); +tsk_restore_flags (current, pflags,PF_MEMALLOC ); + +return ret; +} +EXPORT_SYMBOL (__sk_backlog_rcv);#endif static int sock_set_timeout (long *timeo_p,char __user *optval,int optlen)
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 24/30 mm: add support for non block device backed swap files
In reply to Peter ZijlstraNew addres_space_operations methods are added:
int swapon(struct file *);
int swapoff(struct file *);
int swap_out(struct file *, struct page *, struct writeback_control *); int swap_in(struct file *, struct page *);
When during sys_swapon() the ->swapon() method is found and returns no error the swapper_space.a_ops will proxy to sis->swap_file->f_mapping->a_ops, and make use of ->swap_{out,in}() to write/read swapcache pages.
The ->swapon() method will be used to communicate to the file that the VM relies on it, and the address_space should take adequate measures (like reserving memory for mempools or the like). The ->swapoff() method will be called on sys_swapoff() when ->swapon() was found and returned no error.
This new interface can be used to obviate the need for ->bmap in the swapfile code. A filesystem would need to load (and maybe even allocate) the full block map for a file into memory and pin it there on ->swapon() so that ->swap_{out,in}() have instant access to it. It can be released on ->swapoff().
The reason to provide ->swap_{out,in}() over using {write,read}page() is to
1) make a distinction between swapcache and pagecache pages, and
2) to provide a struct file * for credential context (normally not needed in the context of writepage, as the page content is normally dirtied using either of the following interfaces:
write_{begin,end}()
{prepare,commit}_write()
page_mkwrite()
which do have the file context.
--- Documentation/filesystems/Locking | 22 ++++++++++++++++ Documentation/filesystems/vfs.txt | 18 +++++++++++++ include/linux/buffer_head.h | 2 - include/linux/fs.h | 9 ++++++ include/linux/swap.h | 4 ++ mm/page_io.c | 52 ++++++++++++++++++++++++++++++++++++++ mm/swap_state.c | 4 +- mm/swapfile.c | 32 +++++++++++++++++++++-- 8 files changed, 137 insertions(+), 6 deletions(-)
include/linux/swap.h +4 -0
@@ -121,6 +121,7 @@ enum {SWP_USED = (1 <<0 ),/* is slot in swap_info[] used? */ SWP_WRITEOK = (1 <<1 ),/* ok to write to this swap? */ SWP_ACTIVE = (SWP_USED |SWP_WRITEOK ), +SWP_FILE = (1 <<2 ),/* file swap area */ /* add others here before... */ SWP_SCANNING = (1 << 8), /* refcount in scan_swap_map */ };
@@ -274,6 +275,8 @@ extern void swap_unplug_io_fn(struct bac/* linux/mm/page_io.c */ extern int swap_readpage (struct file *,struct page *);extern int swap_writepage (struct page *page,struct writeback_control *wbc); +extern void swap_sync_page (struct page *page); +extern int swap_set_page_dirty (struct page *page);extern void end_swap_bio_read (struct bio *bio,int err);/* linux/mm/swap_state.c */
@@ -306,6 +309,7 @@ extern unsigned int count_swap_pages(intextern sector_t map_swap_page (struct swap_info_struct *,pgoff_t );extern sector_t swapdev_block (int ,pgoff_t );extern struct swap_info_struct *get_swap_info_struct (unsigned ); +extern struct swap_info_struct *page_swap_info (struct page *);extern int can_share_swap_page (struct page *);extern int remove_exclusive_swap_page (struct page *);extern int remove_exclusive_swap_page_ref (struct page *);
mm/page_io.c +52 -0
82 lines not on this page · raw message
mm/swap_state.c +2 -2
@@ -27,8 +27,8 @@*/ static const struct address_space_operations swap_aops = { .writepage = swap_writepage, - .sync_page = block_sync_page, - .set_page_dirty = __set_page_dirty_nobuffers, + .sync_page = swap_sync_page, + .set_page_dirty = swap_set_page_dirty, .migratepage = migrate_page, };
mm/swapfile.c +29 -3
@@ -1031,6 +1031,14 @@ static void destroy_swap_extents(structlist_del (&se->list);kfree (se); } + +if (sis->flags &SWP_FILE ) { +struct file *swap_file = sis->swap_file; +struct address_space *mapping = swap_file->f_mapping; + + sis->flags &= ~SWP_FILE ; + mapping->a_ops->swapoff (swap_file); + } }/*
@@ -1105,7 +1113,9 @@ add_swap_extent(struct swap_info_struct*/ static int setup_swap_extents (struct swap_info_struct *sis,sector_t *span) { -struct inode *inode; +struct file *swap_file = sis->swap_file; +struct address_space *mapping = swap_file->f_mapping; +struct inode *inode = mapping->host;unsigned blocks_per_page;unsigned long page_no;unsigned blkbits;
@@ -1116,13 +1126,22 @@ static int setup_swap_extents(struct swaint nr_extents =0 ;int ret; - inode = sis->swap_file->f_mapping->host;if (S_ISBLK (inode->i_mode)) { ret =add_swap_extent (sis,0 , sis->max,0 ); *span = sis->pages; goto done; } +if (mapping->a_ops->swapon) { + ret = mapping->a_ops->swapon (swap_file); +if (!ret) { + sis->flags |=SWP_FILE ; + ret =add_swap_extent (sis,0 , sis->max,0 ); + *span = sis->pages; + } + goto done; + } + blkbits = inode->i_blkbits; blocks_per_page =PAGE_SIZE >> blkbits;
@@ -1691,7 +1710,7 @@ asmlinkage long sys_swapon(const char __mutex_lock (&swapon_mutex);spin_lock (&swap_lock); - p->flags =SWP_ACTIVE ; + p->flags |=SWP_WRITEOK ; nr_swap_pages += nr_good_pages; total_swap_pages += nr_good_pages;
@@ -1816,6 +1835,13 @@ get_swap_info_struct(unsigned type)return &swap_info[type]; } +struct swap_info_struct *page_swap_info (struct page *page) +{ +swp_entry_t swap = { .val =page_private (page) }; +BUG_ON (!PageSwapCache (page)); +return &swap_info[swp_type (swap)]; +} +/* * swap_lock prevents swap_map being freed. Don't grab an extra * reference on the swaphandle, it doesn't matter if it becomes unused.
include/linux/fs.h +9 -0
@@ -509,6 +509,15 @@ struct address_space_operations {int (*launder_page) (struct page *);int (*is_partially_uptodate) (struct page *,read_descriptor_t *,unsigned long ); + +/* +* swapfile support +*/ +int (*swapon)(struct file *file); +int (*swapoff)(struct file *file); +int (*swap_out)(struct file *file,struct page *page, +struct writeback_control *wbc); +int (*swap_in)(struct file *file,struct page *page); };/*
Documentation/filesystems/Locking +22 -0
@@ -169,6 +169,10 @@ prototypes: int (*direct_IO)(int, struct kiocb *, const struct iovec *iov, loff_t offset, unsigned long nr_segs); int (*launder_page) (struct page *); + int (*swapon) (struct file *); + int (*swapoff) (struct file *); + int (*swap_out) (struct file *, struct page *, struct writeback_control *); + int (*swap_in) (struct file *, struct page *); locking rules: All except set_page_dirty may block
@@ -190,6 +194,10 @@ invalidatepage: no yes releasepage: no yes direct_IO: no launder_page: no yes +swapon no +swapoff no +swap_out no yes, unlocks +swap_in no yes, unlocks ->prepare_write(), ->commit_write(), ->sync_page() and ->readpage() may be called from the request handler (/dev/loop).
@@ -289,6 +297,20 @@ cleaned, or an error value if not. Note getting mapped back in and redirtied, it needs to be kept locked across the entire operation. + ->swapon() will be called with a non-zero argument on files backing +(non block device backed) swapfiles. A return value of zero indicates success, +in which case this file can be used for backing swapspace. The swapspace +operations will be proxied to the address space operations. + + ->swapoff() will be called in the sys_swapoff() path when ->swapon() +returned success. + + ->swap_out() when swapon() returned success, this method is used to +write the swap page. + + ->swap_in() when swapon() returned success, this method is used to +read the swap page. + Note: currently almost all instances of address_space methods are using BKL for internal serialization and that's one of the worst sources of contention. Normally they are calling library functions (in fs/buffer.c)
include/linux/buffer_head.h +1 -1
@@ -336,7 +336,7 @@ static inline void invalidate_inode_buffstatic inline int remove_inode_buffers (struct inode *inode) {return 1 ; }static inline int sync_mapping_buffers (struct address_space *mapping) {return 0 ; }static inline void invalidate_bdev (struct block_device *bdev) {} - +static inline void block_sync_page (struct page *) { }#endif /* CONFIG_BLOCK */ #endif /* _LINUX_BUFFER_HEAD_H */
Documentation/filesystems/vfs.txt +18 -0
@@ -539,6 +539,11 @@ struct address_space_operations { /* migrate the contents of a page to the specified target */ int (*migratepage) (struct page *, struct page *); int (*launder_page) (struct page *); + int (*swapon)(struct file *); + int (*swapoff)(struct file *); + int (*swap_out)(struct file *file, struct page *page, + struct writeback_control *wbc); + int (*swap_in)(struct file *file, struct page *page); }; writepage: called by the VM to write a dirty page to backing store.
@@ -724,6 +729,19 @@ struct address_space_operations { prevent redirtying the page, it is kept locked during the whole operation. + swapon: Called when swapon is used on a file. A + return value of zero indicates success, in which case this + file can be used to back swapspace. The swapspace operations + will be proxied to this address space's ->swap_{out,in} methods. + + swapoff: Called during swapoff on files where swapon was successfull. + + swap_out: Called to write a swapcache page to a backing store, similar to + writepage. + + swap_in: Called to read a swapcache page from a backing store, similar to + readpage. + The File Object ===============
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 25/30 mm: methods for teaching filesystems about PG_swapcache pages
In reply to Peter ZijlstraIn order to teach filesystems to handle swap cache pages, three new page functions are introduced:
pgoff_t page_file_index(struct page *); loff_t page_file_offset(struct page *); struct address_space *page_file_mapping(struct page *);
page_file_index() - gives the offset of this page in the file in PAGE_CACHE_SIZE blocks. Like page->index is for mapped pages, this function also gives the correct index for PG_swapcache pages.
page_file_offset() - uses page_file_index(), so that it will give the expected result, even for PG_swapcache pages.
page_file_mapping() - gives the mapping backing the actual page; that is for swap cache pages it will give swap_file->f_mapping.
--- include/linux/mm.h | 25 +++++++++++++++++++++++++ include/linux/pagemap.h | 5 +++++ mm/swapfile.c | 19 +++++++++++++++++++ 3 files changed, 49 insertions(+)
include/linux/mm.h +25 -0
@@ -598,6 +598,17 @@ static inline struct address_space *pagereturn mapping; } +extern struct address_space *__page_file_mapping (struct page *); + +static inline +struct address_space *page_file_mapping (struct page *page) +{ +if (unlikely (PageSwapCache (page))) +return __page_file_mapping (page); + +return page->mapping; +} +static inline int PageAnon (struct page *page) {return ((unsigned long )page->mapping &PAGE_MAPPING_ANON ) !=0 ;
@@ -614,6 +625,20 @@ static inline pgoff_t page_index(structreturn page->index; } +extern pgoff_t __page_file_index (struct page *page); + +/* +* Return the file index of the page. Regular pagecache pages use ->index +* whereas swapcache pages use swp_offset(->private) +*/ +static inline pgoff_t page_file_index (struct page *page) +{ +if (unlikely (PageSwapCache (page))) +return __page_file_index (page); + +return page->index; +} +/* * The atomic page->_mapcount, like _count, starts from -1: * so that transitions both from it and to it can be tracked,
include/linux/pagemap.h +5 -0
@@ -148,6 +148,11 @@ static inline loff_t page_offset(structreturn ((loff_t )page->index) <<PAGE_CACHE_SHIFT ; } +static inline loff_t page_file_offset (struct page *page) +{ +return ((loff_t )page_file_index (page)) <<PAGE_CACHE_SHIFT ; +} +static inline pgoff_t linear_page_index (struct vm_area_struct *vma,unsigned long address) {
mm/swapfile.c +19 -0
@@ -1828,6 +1828,25 @@ struct swap_info_struct *page_swap_info( }/* +* out-of-line __page_file_ methods to avoid include hell. +*/ + +struct address_space *__page_file_mapping (struct page *page) +{ +VM_BUG_ON (!PageSwapCache (page)); +return page_swap_info (page)->swap_file->f_mapping; +} +EXPORT_SYMBOL_GPL (__page_file_mapping); + +pgoff_t __page_file_index (struct page *page) +{ +swp_entry_t swap = { .val =page_private (page) }; +VM_BUG_ON (!PageSwapCache (page)); +return swp_offset (swap); +} +EXPORT_SYMBOL_GPL (__page_file_index); + +/* * swap_lock prevents swap_map being freed. Don't grab an extra * reference on the swaphandle, it doesn't matter if it becomes unused. */
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 26/30 nfs: remove mempools
In reply to Peter ZijlstraWith the introduction of the shared dirty page accounting in .19, NFS should not be able to surpise the VM with all dirty pages. Thus it should always be able to free some memory. Hence no more need for mempools.
--- fs/nfs/read.c | 15 +++------------ fs/nfs/write.c | 27 +++++---------------------- 2 files changed, 8 insertions(+), 34 deletions(-)
fs/nfs/read.c +3 -12
@@ -33,13 +33,10 @@ static const struct rpc_call_ops nfs_reastatic const struct rpc_call_ops nfs_read_full_ops;static struct kmem_cache *nfs_rdata_cachep; -static mempool_t *nfs_rdata_mempool; - -#define MIN_POOL_READ (32)struct nfs_read_data *nfs_readdata_alloc (unsigned int pagecount) { -struct nfs_read_data *p =mempool_alloc (nfs_rdata_mempool,GFP_NOFS ); +struct nfs_read_data *p =kmem_cache_alloc (nfs_rdata_cachep,GFP_NOFS );if (p) {memset (p,0 ,sizeof (*p));
@@ -50,7 +47,7 @@ struct nfs_read_data *nfs_readdata_allocelse { p->pagevec =kcalloc (pagecount,sizeof (struct page *),GFP_NOFS );if (!p->pagevec) { -mempool_free (p, nfs_rdata_mempool); +kmem_cache_free (nfs_rdata_cachep, p); p =NULL ; } }
@@ -62,7 +59,7 @@ static void nfs_readdata_free(struct nfs {if (p && (p->pagevec != &p->page_array[0 ]))kfree (p->pagevec); -mempool_free (p, nfs_rdata_mempool); +kmem_cache_free (nfs_rdata_cachep, p); }void nfs_readdata_release (void *data)
@@ -614,16 +611,10 @@ int __init nfs_init_readpagecache(void)if (nfs_rdata_cachep ==NULL )return -ENOMEM ; - nfs_rdata_mempool =mempool_create_slab_pool (MIN_POOL_READ , - nfs_rdata_cachep); -if (nfs_rdata_mempool ==NULL ) -return -ENOMEM ; -return 0 ; }void nfs_destroy_readpagecache (void ) { -mempool_destroy (nfs_rdata_mempool);kmem_cache_destroy (nfs_rdata_cachep); }
fs/nfs/write.c +5 -22
@@ -28,9 +28,6 @@#define NFSDBG_FACILITY NFSDBG_PAGECACHE -#define MIN_POOL_WRITE (32) -#define MIN_POOL_COMMIT (4) -/* * Local function declarations */
@@ -45,12 +42,10 @@ static const struct rpc_call_ops nfs_wristatic const struct rpc_call_ops nfs_commit_ops;static struct kmem_cache *nfs_wdata_cachep; -static mempool_t *nfs_wdata_mempool; -static mempool_t *nfs_commit_mempool;struct nfs_write_data *nfs_commitdata_alloc (void ) { -struct nfs_write_data *p =mempool_alloc (nfs_commit_mempool,GFP_NOFS ); +struct nfs_write_data *p =kmem_cache_alloc (nfs_wdata_cachep,GFP_NOFS );if (p) {memset (p,0 ,sizeof (*p));
@@ -63,12 +58,12 @@ void nfs_commit_free(struct nfs_write_da {if (p && (p->pagevec != &p->page_array[0 ]))kfree (p->pagevec); -mempool_free (p, nfs_commit_mempool); +kmem_cache_free (nfs_wdata_cachep, p); }struct nfs_write_data *nfs_writedata_alloc (unsigned int pagecount) { -struct nfs_write_data *p =mempool_alloc (nfs_wdata_mempool,GFP_NOFS ); +struct nfs_write_data *p =kmem_cache_alloc (nfs_wdata_cachep,GFP_NOFS );if (p) {memset (p,0 ,sizeof (*p));
@@ -79,7 +74,7 @@ struct nfs_write_data *nfs_writedata_allelse { p->pagevec =kcalloc (pagecount,sizeof (struct page *),GFP_NOFS );if (!p->pagevec) { -mempool_free (p, nfs_wdata_mempool); +kmem_cache_free (nfs_wdata_cachep, p); p =NULL ; } }
@@ -91,7 +86,7 @@ static void nfs_writedata_free(struct nf {if (p && (p->pagevec != &p->page_array[0 ]))kfree (p->pagevec); -mempool_free (p, nfs_wdata_mempool); +kmem_cache_free (nfs_wdata_cachep, p); }void nfs_writedata_release (void *data)
@@ -1552,16 +1547,6 @@ int __init nfs_init_writepagecache(void)if (nfs_wdata_cachep ==NULL )return -ENOMEM ; - nfs_wdata_mempool =mempool_create_slab_pool (MIN_POOL_WRITE , - nfs_wdata_cachep); -if (nfs_wdata_mempool ==NULL ) -return -ENOMEM ; - - nfs_commit_mempool =mempool_create_slab_pool (MIN_POOL_COMMIT , - nfs_wdata_cachep); -if (nfs_commit_mempool ==NULL ) -return -ENOMEM ; -/* * NFS congestion size, scale with available memory. *
@@ -1587,8 +1572,6 @@ int __init nfs_init_writepagecache(void)void nfs_destroy_writepagecache (void ) { -mempool_destroy (nfs_commit_mempool); -mempool_destroy (nfs_wdata_mempool);kmem_cache_destroy (nfs_wdata_cachep); }
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 26/30] nfs: remove mempools
Quoted 3 lines · Peter Zijlstra
With the introduction of the shared dirty page accounting in .19, NFS should not be able to surpise the VM with all dirty pages. Thus it should always be able to free some memory. Hence no more need for mempools.
It seems like a very backward step to me to go from a hard guarantee to some heuristic that could break for someone in some particular setup.
Filling with dirty pages isn't the only way to exaust free reclaimable memory remember, it can also happen maybe due to mlock or kernel allocations.
Is there pressing reason to remove them?
Quoted 139 lines
Signed-off-by Peter Zijlstra <[email protected]>--- fs/nfs/read.c | 15 +++------------ fs/nfs/write.c | 27 +++++---------------------- 2 files changed, 8 insertions(+), 34 deletions(-)Index:
linux-2.6/fs/nfs/read.c
===================================================================fs/nfs/read.c +3
-12@@ -33,13 +33,10 @@ static const struct rpc_call_ops nfs_reastatic const struct rpc_call_ops nfs_read_full_ops;static struct kmem_cache *nfs_rdata_cachep; -static mempool_t *nfs_rdata_mempool; - -#define MIN_POOL_READ (32)struct nfs_read_data *nfs_readdata_alloc (unsigned int pagecount) { -struct nfs_read_data *p =mempool_alloc (nfs_rdata_mempool,GFP_NOFS ); +struct nfs_read_data *p =kmem_cache_alloc (nfs_rdata_cachep,GFP_NOFS );if (p) {memset (p,0 ,sizeof (*p));@@ -50,7 +47,7 @@ struct nfs_read_data *nfs_readdata_allocelse { p->pagevec =kcalloc (pagecount,sizeof (struct page *),GFP_NOFS );if (!p->pagevec) { -mempool_free (p, nfs_rdata_mempool); +kmem_cache_free (nfs_rdata_cachep, p); p =NULL ; } }@@ -62,7 +59,7 @@ static void nfs_readdata_free(struct nfs {if (p && (p->pagevec != &p->page_array[0 ]))kfree (p->pagevec); -mempool_free (p, nfs_rdata_mempool); +kmem_cache_free (nfs_rdata_cachep, p); }void nfs_readdata_release (void *data)@@ -614,16 +611,10 @@ int __init nfs_init_readpagecache(void)if (nfs_rdata_cachep ==NULL )return -ENOMEM ; - nfs_rdata_mempool =mempool_create_slab_pool (MIN_POOL_READ , - nfs_rdata_cachep); -if (nfs_rdata_mempool ==NULL ) -return -ENOMEM ; -return 0 ; }void nfs_destroy_readpagecache (void ) { -mempool_destroy (nfs_rdata_mempool);kmem_cache_destroy (nfs_rdata_cachep); }Index:
linux-2.6/fs/nfs/write.c
===================================================================fs/nfs/write.c +5
-20@@ -28,9 +28,6 @@#define NFSDBG_FACILITY NFSDBG_PAGECACHE -#define MIN_POOL_WRITE (32) -#define MIN_POOL_COMMIT (4) -/* * Local function declarations */ @@ -45,12 +42,10 @@ static const struct rpc_call_ops nfs_wristatic const struct rpc_call_ops nfs_commit_ops;static struct kmem_cache *nfs_wdata_cachep; -static mempool_t *nfs_wdata_mempool; -static mempool_t *nfs_commit_mempool;struct nfs_write_data *nfs_commitdata_alloc (void ) { -struct nfs_write_data *p =mempool_alloc (nfs_commit_mempool,GFP_NOFS ); +struct nfs_write_data *p =kmem_cache_alloc (nfs_wdata_cachep,GFP_NOFS );if (p) {memset (p,0 ,sizeof (*p));@@ -63,12 +58,12 @@ void nfs_commit_free(struct nfs_write_da {if (p && (p->pagevec != &p->page_array[0 ]))kfree (p->pagevec); -mempool_free (p, nfs_commit_mempool); +kmem_cache_free (nfs_wdata_cachep, p); }struct nfs_write_data *nfs_writedata_alloc (unsigned int pagecount) { -struct nfs_write_data *p =mempool_alloc (nfs_wdata_mempool,GFP_NOFS ); +struct nfs_write_data *p =kmem_cache_alloc (nfs_wdata_cachep,GFP_NOFS );if (p) {memset (p,0 ,sizeof (*p));@@ -79,7 +74,7 @@ struct nfs_write_data *nfs_writedata_allelse { p->pagevec =kcalloc (pagecount,sizeof (struct page *),GFP_NOFS );if (!p->pagevec) { -mempool_free (p, nfs_wdata_mempool); +kmem_cache_free (nfs_wdata_cachep, p); p =NULL ; } }@@ -91,7 +86,7 @@ static void nfs_writedata_free(struct nf {if (p && (p->pagevec != &p->page_array[0 ]))kfree (p->pagevec); -mempool_free (p, nfs_wdata_mempool); +kmem_cache_free (nfs_wdata_cachep, p); }void nfs_writedata_release (void *data)@@ -1552,16 +1547,6 @@ int __init nfs_init_writepagecache(void)if (nfs_wdata_cachep ==NULL )return -ENOMEM ; - nfs_wdata_mempool =mempool_create_slab_pool (MIN_POOL_WRITE , - nfs_wdata_cachep); -if (nfs_wdata_mempool ==NULL ) -return -ENOMEM ; - - nfs_commit_mempool =mempool_create_slab_pool (MIN_POOL_COMMIT , - nfs_wdata_cachep); -if (nfs_commit_mempool ==NULL ) -return -ENOMEM ; -/* * NFS congestion size, scale with available memory. *
fs/nfs/write.c int __init nfs_init_writepagecache(void) · line 1576
Quoted 7 lines
fs/nfs/write.c +0
-2@@ -1587,8 +1572,6 @@ int __init nfs_init_writepagecache(void)void nfs_destroy_writepagecache (void ) { -mempool_destroy (nfs_commit_mempool); -mempool_destroy (nfs_wdata_mempool);kmem_cache_destroy (nfs_wdata_cachep); }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 26/30] nfs: remove mempools
Quoted 9 lines · Nick Piggin
Quoted 3 lines · Peter Zijlstra
With the introduction of the shared dirty page accounting in .19, NFS should not be able to surpise the VM with all dirty pages. Thus it should always be able to free some memory. Hence no more need for mempools.
It seems like a very backward step to me to go from a hard guarantee to some heuristic that could break for someone in some particular setup.
Quoted 5 lines
Filling with dirty pages isn't the only way to exaust free reclaimable memory remember, it can also happen maybe due to mlock or kernel allocations.
Is there pressing reason to remove them?
There was some funny interaction between mempools and PF_MEMALLOC as used to write out swap pages iirc.
Specifially, the mempool would strip it and not provide memory even though we needed it.
I've never hit a deadlock due to this patch in my testing, although admittedly there might be a hole in my testing.
I can either 'fix' mempools, or replace it with the reserve framework introduced earlier in this patch-set.
Quoted 140 lines
Quoted 140 lines
Signed-off-by Peter Zijlstra <[email protected]>--- fs/nfs/read.c | 15 +++------------ fs/nfs/write.c | 27 +++++---------------------- 2 files changed, 8 insertions(+), 34 deletions(-)Index:
linux-2.6/fs/nfs/read.c
===================================================================fs/nfs/read.c +3
-12@@ -33,13 +33,10 @@ static const struct rpc_call_ops nfs_reastatic const struct rpc_call_ops nfs_read_full_ops;static struct kmem_cache *nfs_rdata_cachep; -static mempool_t *nfs_rdata_mempool; - -#define MIN_POOL_READ (32)struct nfs_read_data *nfs_readdata_alloc (unsigned int pagecount) { -struct nfs_read_data *p =mempool_alloc (nfs_rdata_mempool,GFP_NOFS ); +struct nfs_read_data *p =kmem_cache_alloc (nfs_rdata_cachep,GFP_NOFS );if (p) {memset (p,0 ,sizeof (*p));@@ -50,7 +47,7 @@ struct nfs_read_data *nfs_readdata_allocelse { p->pagevec =kcalloc (pagecount,sizeof (struct page *),GFP_NOFS );if (!p->pagevec) { -mempool_free (p, nfs_rdata_mempool); +kmem_cache_free (nfs_rdata_cachep, p); p =NULL ; } }@@ -62,7 +59,7 @@ static void nfs_readdata_free(struct nfs {if (p && (p->pagevec != &p->page_array[0 ]))kfree (p->pagevec); -mempool_free (p, nfs_rdata_mempool); +kmem_cache_free (nfs_rdata_cachep, p); }void nfs_readdata_release (void *data)@@ -614,16 +611,10 @@ int __init nfs_init_readpagecache(void)if (nfs_rdata_cachep ==NULL )return -ENOMEM ; - nfs_rdata_mempool =mempool_create_slab_pool (MIN_POOL_READ , - nfs_rdata_cachep); -if (nfs_rdata_mempool ==NULL ) -return -ENOMEM ; -return 0 ; }void nfs_destroy_readpagecache (void ) { -mempool_destroy (nfs_rdata_mempool);kmem_cache_destroy (nfs_rdata_cachep); }Index:
linux-2.6/fs/nfs/write.c
===================================================================fs/nfs/write.c +5
-20@@ -28,9 +28,6 @@#define NFSDBG_FACILITY NFSDBG_PAGECACHE -#define MIN_POOL_WRITE (32) -#define MIN_POOL_COMMIT (4) -/* * Local function declarations */ @@ -45,12 +42,10 @@ static const struct rpc_call_ops nfs_wristatic const struct rpc_call_ops nfs_commit_ops;static struct kmem_cache *nfs_wdata_cachep; -static mempool_t *nfs_wdata_mempool; -static mempool_t *nfs_commit_mempool;struct nfs_write_data *nfs_commitdata_alloc (void ) { -struct nfs_write_data *p =mempool_alloc (nfs_commit_mempool,GFP_NOFS ); +struct nfs_write_data *p =kmem_cache_alloc (nfs_wdata_cachep,GFP_NOFS );if (p) {memset (p,0 ,sizeof (*p));@@ -63,12 +58,12 @@ void nfs_commit_free(struct nfs_write_da {if (p && (p->pagevec != &p->page_array[0 ]))kfree (p->pagevec); -mempool_free (p, nfs_commit_mempool); +kmem_cache_free (nfs_wdata_cachep, p); }struct nfs_write_data *nfs_writedata_alloc (unsigned int pagecount) { -struct nfs_write_data *p =mempool_alloc (nfs_wdata_mempool,GFP_NOFS ); +struct nfs_write_data *p =kmem_cache_alloc (nfs_wdata_cachep,GFP_NOFS );if (p) {memset (p,0 ,sizeof (*p));@@ -79,7 +74,7 @@ struct nfs_write_data *nfs_writedata_allelse { p->pagevec =kcalloc (pagecount,sizeof (struct page *),GFP_NOFS );if (!p->pagevec) { -mempool_free (p, nfs_wdata_mempool); +kmem_cache_free (nfs_wdata_cachep, p); p =NULL ; } }@@ -91,7 +86,7 @@ static void nfs_writedata_free(struct nf {if (p && (p->pagevec != &p->page_array[0 ]))kfree (p->pagevec); -mempool_free (p, nfs_wdata_mempool); +kmem_cache_free (nfs_wdata_cachep, p); }void nfs_writedata_release (void *data)@@ -1552,16 +1547,6 @@ int __init nfs_init_writepagecache(void)if (nfs_wdata_cachep ==NULL )return -ENOMEM ; - nfs_wdata_mempool =mempool_create_slab_pool (MIN_POOL_WRITE , - nfs_wdata_cachep); -if (nfs_wdata_mempool ==NULL ) -return -ENOMEM ; - - nfs_commit_mempool =mempool_create_slab_pool (MIN_POOL_COMMIT , - nfs_wdata_cachep); -if (nfs_commit_mempool ==NULL ) -return -ENOMEM ; -/* * NFS congestion size, scale with available memory. * @@ -1587,8 +1572,6 @@ int __init nfs_init_writepagecache(void)
Quoted 6 lines
fs/nfs/write.c int __init nfs_init_writepagecache(void) · line 1576
Quoted 6 lines
fs/nfs/write.c +0
-2void nfs_destroy_writepagecache (void ) { -mempool_destroy (nfs_commit_mempool); -mempool_destroy (nfs_wdata_mempool);kmem_cache_destroy (nfs_wdata_cachep); }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 27/30 nfs: teach the NFS client how to treat PG_swapcache pages
In reply to Peter ZijlstraReplace all relevant occurences of page->index and page->mapping in the NFS client with the new page_file_index() and page_file_mapping() functions.
--- fs/nfs/file.c | 6 +++--- fs/nfs/internal.h | 7 ++++--- fs/nfs/pagelist.c | 6 +++--- fs/nfs/read.c | 6 +++--- fs/nfs/write.c | 53 +++++++++++++++++++++++++++-------------------------- 5 files changed, 40 insertions(+), 38 deletions(-)
fs/nfs/file.c +3 -3
@@ -413,7 +413,7 @@ static void nfs_invalidate_page(struct pif (offset !=0 )return ;/* Cancel any unstarted writes on this page */ -nfs_wb_page_cancel (page->mapping->host, page); +nfs_wb_page_cancel (page_file_mapping (page)->host, page); }static int nfs_release_page (struct page *page,gfp_t gfp)
@@ -426,7 +426,7 @@ static int nfs_release_page(struct pagestatic int nfs_launder_page (struct page *page) { -struct inode *inode = page->mapping->host; +struct inode *inode =page_file_mapping (page)->host;dfprintk (PAGECACHE ,"NFS: launder_page(%ld, %llu)\n" , inode->i_ino, (long long )page_offset (page));
@@ -462,7 +462,7 @@ static int nfs_vm_page_mkwrite(struct vm (long long)page_offset(page));lock_page (page); - mapping = page->mapping; + mapping =page_file_mapping (page);if (mapping != dentry->d_inode->i_mapping) goto out_unlock;
fs/nfs/pagelist.c +3 -3
@@ -76,11 +76,11 @@ nfs_create_request(struct nfs_open_conte* update_nfs_request below if the region is not locked. */ req->wb_page = page;atomic_set (&req->wb_complete,0 ); - req->wb_index = page->index; + req->wb_index =page_file_index (page);page_cache_get (page);BUG_ON (PagePrivate (page));BUG_ON (!PageLocked (page)); -BUG_ON (page->mapping->host != inode); +BUG_ON (page_file_mapping (page)->host != inode); req->wb_offset = offset; req->wb_pgbase = offset; req->wb_bytes = count;
@@ -376,7 +376,7 @@ void nfs_pageio_cond_complete(struct nfs* nfs_scan_list - Scan a list for matching requests * @nfsi: NFS inode * @dst: Destination list -* @idx_start: lower bound of page->index to scan +* @idx_start: lower bound of page_file_index(page) to scan * @npages: idx_start + npages sets the upper bound to scan. * @tag: tag to scan for *
fs/nfs/read.c +3 -3
@@ -474,11 +474,11 @@ static const struct rpc_call_ops nfs_reaint nfs_readpage (struct file *file,struct page *page) {struct nfs_open_context *ctx; -struct inode *inode = page->mapping->host; +struct inode *inode =page_file_mapping (page)->host;int error;dprintk ("NFS: nfs_readpage (%p %ld@%lu)\n" , - page,PAGE_CACHE_SIZE , page->index); + page,PAGE_CACHE_SIZE ,page_file_index (page));nfs_inc_stats (inode,NFSIOS_VFSREADPAGE );nfs_add_stats (inode,NFSIOS_READPAGES ,1 );
@@ -525,7 +525,7 @@ static int readpage_async_filler(void *data, struct page *page) {struct nfs_readdesc *desc = (struct nfs_readdesc *)data; -struct inode *inode = page->mapping->host; +struct inode *inode =page_file_mapping (page)->host;struct nfs_page *new;unsigned int len;int error;
fs/nfs/write.c +27 -26
191 lines not on this page · raw message
fs/nfs/internal.h +4 -3
@@ -253,13 +253,14 @@ void nfs_super_set_maxbytes(struct superstatic inline unsigned int nfs_page_length (struct page *page) { -loff_t i_size =i_size_read (page->mapping->host); +loff_t i_size =i_size_read (page_file_mapping (page)->host);if (i_size >0 ) { +pgoff_t page_index =page_file_index (page);pgoff_t end_index = (i_size -1 ) >>PAGE_CACHE_SHIFT ; -if (page->index < end_index) +if (page_index < end_index)return PAGE_CACHE_SIZE ; -if (page->index == end_index) +if (page_index == end_index)return ((i_size -1 ) & ~PAGE_CACHE_MASK ) +1 ; }return 0 ;
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 28/30 nfs: disable data cache revalidation for swapfiles
In reply to Peter ZijlstraDo as Trond suggested:
http://lkml.org/lkml/2006/8/25/348
Disable NFS data cache revalidation on swap files since it doesn't really make sense to have other clients change the file while you are using it.
Thereby we can stop setting PG_private on swap pages, since there ought to be no further races with invalidate_inode_pages2() to deal with.
And since we cannot set PG_private we cannot use page->private (which is already used by PG_swapcache pages anyway) to store the nfs_page. Thus augment the new nfs_page_find_request logic.
--- fs/nfs/inode.c | 6 ++++ fs/nfs/write.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 64 insertions(+), 13 deletions(-)
fs/nfs/inode.c +6 -0
@@ -824,6 +824,12 @@ int nfs_revalidate_mapping_nolock(structstruct nfs_inode *nfsi =NFS_I (inode);int ret =0 ; +/* +* swapfiles are not supposed to be shared. +*/ +if (IS_SWAPFILE (inode)) + goto out; +if ((nfsi->cache_validity &NFS_INO_REVAL_PAGECACHE ) ||nfs_attribute_timeout (inode) ||NFS_STALE (inode)) { ret =__nfs_revalidate_inode (NFS_SERVER (inode), inode);
fs/nfs/write.c +58 -13
120 lines not on this page · raw message
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 29/30 nfs: enable swap on NFS
In reply to Peter ZijlstraImplement all the new swapfile a_ops for NFS. This will set the NFS socket to SOCK_MEMALLOC and run socket reconnect under PF_MEMALLOC as well as reset SOCK_MEMALLOC before engaging the protocol ->connect() method.
PF_MEMALLOC should allow the allocation of struct socket and related objects and the early (re)setting of SOCK_MEMALLOC should allow us to receive the packets required for the TCP connection buildup.
(swapping continues over a server reset during heavy network traffic)
--- fs/Kconfig | 17 ++++++++++ fs/nfs/file.c | 18 ++++++++++ fs/nfs/write.c | 22 +++++++++++++ include/linux/nfs_fs.h | 2 + include/linux/sunrpc/xprt.h | 5 ++- net/sunrpc/sched.c | 9 ++++- net/sunrpc/xprtsock.c | 73 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 143 insertions(+), 3 deletions(-)
fs/nfs/file.c +18 -0
@@ -434,6 +434,18 @@ static int nfs_launder_page(struct pagereturn nfs_wb_page (inode, page); } +#ifdef CONFIG_NFS_SWAP +static int nfs_swapon (struct file *file) +{ +return xs_swapper (NFS_CLIENT (file->f_mapping->host)->cl_xprt,1 ); +} + +static int nfs_swapoff (struct file *file) +{ +return xs_swapper (NFS_CLIENT (file->f_mapping->host)->cl_xprt,0 ); +} +#endif +const struct address_space_operations nfs_file_aops = { .readpage = nfs_readpage, .readpages = nfs_readpages,
@@ -446,6 +458,12 @@ const struct address_space_operations nf .releasepage = nfs_release_page, .direct_IO = nfs_direct_IO, .launder_page = nfs_launder_page, +#ifdef CONFIG_NFS_SWAP + .swapon = nfs_swapon, + .swapoff = nfs_swapoff, + .swap_out = nfs_swap_out, + .swap_in = nfs_readpage, +#endif };static int nfs_vm_page_mkwrite (struct vm_area_struct *vma,struct page *page)
fs/nfs/write.c +22 -0
@@ -330,6 +330,28 @@ int nfs_writepage(struct page *page, strreturn ret; } +static int nfs_writepage_setup (struct nfs_open_context *ctx,struct page *page, +unsigned int offset,unsigned int count); + +int nfs_swap_out (struct file *file,struct page *page, +struct writeback_control *wbc) +{ +struct nfs_open_context *ctx =nfs_file_open_context (file); +int status; + + status =nfs_writepage_setup (ctx, page,0 ,nfs_page_length (page)); +if (status <0 ) { +nfs_set_pageerror (page); + goto out; + } + + status =nfs_writepage_locked (page, wbc); + +out: +unlock_page (page); +return status; +} +static int nfs_writepages_callback (struct page *page,struct writeback_control *wbc,void *data) {int ret;
include/linux/nfs_fs.h +2 -0
@@ -463,6 +463,8 @@ extern int nfs_flush_incompatible(strucextern int nfs_updatepage (struct file *,struct page *,unsigned int ,unsigned int );extern int nfs_writeback_done (struct rpc_task *,struct nfs_write_data *);extern void nfs_writedata_release (void *); +extern int nfs_swap_out (struct file *file,struct page *page, +struct writeback_control *wbc);/* * Try to write back everything synchronously (but check the
fs/Kconfig +17 -0
@@ -1692,6 +1692,18 @@ config ROOT_NFS Most people say N here. +config NFS_SWAP + bool "Provide swap over NFS support" + default n + depends on NFS_FS + select SUNRPC_SWAP + help + This option enables swapon to work on files located on NFS mounts. + + For more details, see Documentation/network-swap.txt + + If unsure, say N. + config NFSD tristate "NFS server support" depends on INET
@@ -1813,6 +1825,11 @@ config SUNRPC_XPRT_RDMA If unsure, say N. +config SUNRPC_SWAP + def_bool n + depends on SUNRPC + select NETVM + config RPCSEC_GSS_KRB5 tristate "Secure RPC: Kerberos V mechanism (EXPERIMENTAL)" depends on SUNRPC && EXPERIMENTAL
include/linux/sunrpc/xprt.h +4 -1
@@ -147,7 +147,9 @@ struct rpc_xprt {unsigned int max_reqs;/* total slots */ unsigned long state;/* transport state */ unsigned char shutdown : 1, /* being shut down */ - resvport : 1; /* use a reserved port */ + resvport : 1, /* use a reserved port */ + swapper : 1; /* we're swapping over this +transport */ unsigned int bind_index;/* bind function index */ /*
@@ -249,6 +251,7 @@ void xprt_release_rqst_cong(struct rpcvoid xprt_disconnect_done (struct rpc_xprt *xprt);void xprt_force_disconnect (struct rpc_xprt *xprt);void xprt_conditional_disconnect (struct rpc_xprt *xprt,unsigned int cookie); +int xs_swapper (struct rpc_xprt *xprt,int enable);/* * Reserved bit positions in xprt->state
net/sunrpc/sched.c +7 -2
@@ -729,7 +729,10 @@ struct rpc_buffer {void *rpc_malloc (struct rpc_task *task,size_t size) {struct rpc_buffer *buf; -gfp_t gfp =RPC_IS_SWAPPER (task) ?GFP_ATOMIC :GFP_NOWAIT ; +gfp_t gfp =GFP_NOWAIT ; + +if (RPC_IS_SWAPPER (task)) + gfp |= __GFP_MEMALLOC; size +=sizeof (struct rpc_buffer );if (size <=RPC_BUFFER_MAXSIZE )
@@ -800,6 +803,8 @@ static void rpc_init_task(struct rpc_taskref_get (&task->tk_client->cl_kref);if (task->tk_client->cl_softrtry) task->tk_flags |=RPC_TASK_SOFT ; +if (task->tk_client->cl_xprt->swapper) + task->tk_flags |=RPC_TASK_SWAPPER ; }if (task->tk_ops->rpc_call_prepare !=NULL )
@@ -825,7 +830,7 @@ static void rpc_init_task(struct rpc_tasstatic struct rpc_task *rpc_alloc_task (void ) { -return (struct rpc_task *)mempool_alloc (rpc_task_mempool,GFP_NOFS ); +return (struct rpc_task *)mempool_alloc (rpc_task_mempool,GFP_NOIO ); }/*
net/sunrpc/xprtsock.c +73 -0
159 lines not on this page · raw message
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 30/30 nfs: fix various memory recursions possible with swap over NFS.
In reply to Peter ZijlstraGFP_NOFS is not enough, since swap traffic is IO, hence fall back to GFP_NOIO.
--- fs/nfs/pagelist.c | 2 +- fs/nfs/write.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
fs/nfs/write.c +3 -3
@@ -45,7 +45,7 @@ static struct kmem_cache *nfs_wdata_cachstruct nfs_write_data *nfs_commitdata_alloc (void ) { -struct nfs_write_data *p =kmem_cache_alloc (nfs_wdata_cachep,GFP_NOFS ); +struct nfs_write_data *p =kmem_cache_alloc (nfs_wdata_cachep,GFP_NOIO );if (p) {memset (p,0 ,sizeof (*p));
@@ -63,7 +63,7 @@ void nfs_commit_free(struct nfs_write_dastruct nfs_write_data *nfs_writedata_alloc (unsigned int pagecount) { -struct nfs_write_data *p =kmem_cache_alloc (nfs_wdata_cachep,GFP_NOFS ); +struct nfs_write_data *p =kmem_cache_alloc (nfs_wdata_cachep,GFP_NOIO );if (p) {memset (p,0 ,sizeof (*p));
@@ -72,7 +72,7 @@ struct nfs_write_data *nfs_writedata_allif (pagecount <=ARRAY_SIZE (p->page_array)) p->pagevec = p->page_array;else { - p->pagevec =kcalloc (pagecount,sizeof (struct page *),GFP_NOFS ); + p->pagevec =kcalloc (pagecount,sizeof (struct page *),GFP_NOIO );if (!p->pagevec) {kmem_cache_free (nfs_wdata_cachep, p); p =NULL ;
fs/nfs/pagelist.c +1 -1
@@ -27,7 +27,7 @@ static inline struct nfs_page *nfs_page_alloc (void) {struct nfs_page *p; - p =kmem_cache_alloc (nfs_page_cachep,GFP_KERNEL ); + p =kmem_cache_alloc (nfs_page_cachep,GFP_NOIO );if (p) {memset (p,0 ,sizeof (*p));INIT_LIST_HEAD (&p->wb_list);
Signature · 5 lines
-- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 30/30] nfs: fix various memory recursions possible with swap over NFS.
Quoted 1 line
GFP_NOFSis not enough, since swap traffic is IO, hence fall back toGFP_NOIO.
this comment imply turn on GFP_NOIO, but the code is s/NOFS/NOIO/. why?
Review
Quoted 4 lines
struct
nfs_write_data*nfs_commitdata_alloc(void){(quoted diff) +1
-1- struct nfs_write_data *p = kmem_cache_alloc(nfs_wdata_cachep, GFP_NOFS); + struct nfs_write_data *p = kmem_cache_alloc(nfs_wdata_cachep, GFP_NOIO);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 30/30] nfs: fix various memory recursions possible with swap over NFS.
Quoted 3 lines · KOSAKI Motohiro
Quoted 1 line
GFP_NOFSis not enough, since swap traffic is IO, hence fall back toGFP_NOIO.this comment imply turn on
GFP_NOIO, but the code is s/NOFS/NOIO/. why?
Does the misunderstanding stem from the use of 'enough'?
GFP_NOFS is _more_ permissive than GFP_NOIO in that it will initiate IO, just not of any filesystem data.
The problem is that previuosly NOFS was correct because that avoids recursion into the NFS code, it now is not, because also IO (swap) can lead to this recursion.
Therefore we must tighten the restriction and use NOIO.
Quoted 8 lines
Quoted 4 lines
struct
nfs_write_data*nfs_commitdata_alloc(void){(quoted diff) +1
-1- struct nfs_write_data *p = kmem_cache_alloc(nfs_wdata_cachep, GFP_NOFS); + struct nfs_write_data *p = kmem_cache_alloc(nfs_wdata_cachep, GFP_NOIO);
Re: [PATCH 30/30] nfs: fix various memory recursions possible with swap over NFS.
Quoted 7 lines · KOSAKI Motohiro
Quoted 3 lines
Quoted 1 line
GFP_NOFSis not enough, since swap traffic is IO, hence fall back toGFP_NOIO.this comment imply turn on
GFP_NOIO, but the code is s/NOFS/NOIO/. why?Does the misunderstanding stem from the use of 'enough'?
Quoted 8 lines
GFP_NOFSis _more_ permissive thanGFP_NOIOin that it will initiate IO, just not of any filesystem data.The problem is that previuosly NOFS was correct because that avoids recursion into the NFS code, it now is not, because also IO (swap) can lead to this recursion.
Thanks nicer explain.
So, I hope add above 3 line to patch description.
Cheers!
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 30/30] nfs: fix various memory recursions possible with swap over NFS.
Quoted 12 lines · KOSAKI Motohiro
Quoted 10 lines · KOSAKI Motohiro
Quoted 3 lines
Quoted 1 line
GFP_NOFSis not enough, since swap traffic is IO, hence fall back toGFP_NOIO.this comment imply turn on
GFP_NOIO, but the code is s/NOFS/NOIO/. why?Does the misunderstanding stem from the use of 'enough'?
GFP_NOFSis _more_ permissive thanGFP_NOIOin that it will initiate IO, just not of any filesystem data.
Quoted 7 lines
Quoted 3 lines
The problem is that previuosly NOFS was correct because that avoids recursion into the NFS code, it now is not, because also IO (swap) can lead to this recursion.
Thanks nicer explain.
So, I hope add above 3 line to patch description.
Done, thanks!
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Peter Zijlstra
Latest version of the swap over nfs work.
Patches are against: v2.6.26-rc8-mm1
I still need to write some more comments in the reservation code.
Pekka, it uses
ksize(), please have a look.
Quoted 7 lines
This version also deals with network namespaces. Two things where I could do with some suggestsion:
- currently the sysctl code uses
current->nrproxy.net_nsto obtain the current network namespace- the ipv6 route cache code has some initialization order issues
Daniel, have you ever found time to look at my namespace issues?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 12 lines · Peter Zijlstra
Quoted 11 lines · Peter Zijlstra
Latest version of the swap over nfs work.
Patches are against: v2.6.26-rc8-mm1
I still need to write some more comments in the reservation code.
Pekka, it uses
ksize(), please have a look.This version also deals with network namespaces. Two things where I could do with some suggestsion:
Quoted 6 lines
Quoted 4 lines
- currently the sysctl code uses
current->nrproxy.net_nsto obtain the current network namespace- the ipv6 route cache code has some initialization order issues
Daniel, have you ever found time to look at my namespace issues?
Oops, no. I was busy and I forgot, sorry.
Let me review the sysctl vs namespace part.
Thanks
-- Daniel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>