Skip to contentSkip to conversation

GIT 1.0.0

ANNOUNCE Junio C Hamano 17 participants 36 messages Dec 21, 2005 – Jan 4, 2006

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

GIT 1.0.0 is found at the usual places:

	Tarball	http://www.kernel.org/pub/software/scm/git/
	RPM	http://www.kernel.org/pub/software/scm/git/RPMS/
	Debian	http://www.kernel.org/pub/software/scm/git/debian/
	GIT	git://git.kernel.org/pub/scm/git/git.git/

The name "1.0.0" ought to mean a significant milestone, but actually it is not. Pre 1.0 version has been in production use by the kernel folks for quite some time, and the changes since 1.0rc are pretty small and primarily consist of documenation updates, clone/fetch enhancements and miscellaneous bugfixes.

Thank you all who gave patches, comments and time.

Happy hacking, and a little early ho-ho-ho.

#1 lore raw

[POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

I wonder if the 32 and 192 bytes caches are worth to be declared in include/linux/kmalloc_sizes.h, at least on x86_64

(x86_64 : PAGE_SIZE = 4096, L1_CACHE_BYTES = 64)

On my machines, I can say that the 32 and 192 sizes could be avoided in favor in spending less cpu cycles in __find_general_cachep()

Could some of you post the result of the following command on your machines :

# grep "size-" /proc/slabinfo |grep -v DMA|cut -c1-40
size-131072            0      0 131072
size-65536             0      0  65536
size-32768             2      2  32768
size-16384             0      0  16384
size-8192             13     13   8192
size-4096            161    161   4096
size-2048          40564  42976   2048
size-1024            681    800   1024
size-512           19792  37168    512
size-256              81    105    256
size-192            1218   1280    192

size-64 31278 86907 64
size-128 5457 10380 128
size-32 594 784 32

Thank you

PS : I have no idea why the last lines (size-192, 64, 128, 32) are not ordered...

Eric

#2 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

From: Eric Dumazet <[email protected]>
Date: Wed, 21 Dec 2005 10:11:51 +0100

Quoted 1 line

Could some of you post the result of the following command on your machines :

sparc64, PAGE_SIZE=8192, L1_CACHE_BYTES=32

size-131072 0 0 131072

size-65536            13     13  65536  
size-32768             2      2  32768  
size-16384             2      2  16384  
size-8192             67     67   8192  
size-4096             75     76   4096  
size-2048            303    308   2048  
size-1024            176    176   1024  
size-512             251    255    512  
size-256             217    217    256  
size-192            1230   1230    192  
size-128             106    122    128  

size-96 1098 1134 96
size-64 29387 30226 64

#4 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Eric Dumazet
Quoted 23 lines · Eric Dumazet

I wonder if the 32 and 192 bytes caches are worth to be declared in include/linux/kmalloc_sizes.h, at least on x86_64

(x86_64 : PAGE_SIZE = 4096, L1_CACHE_BYTES = 64)

On my machines, I can say that the 32 and 192 sizes could be avoided in favor in spending less cpu cycles in __find_general_cachep()

Could some of you post the result of the following command on your machines :

# grep "size-" /proc/slabinfo |grep -v DMA|cut -c1-40
size-131072            0      0 131072
size-65536             0      0  65536
size-32768             2      2  32768
size-16384             0      0  16384
size-8192             13     13   8192
size-4096            161    161   4096
size-2048          40564  42976   2048
size-1024            681    800   1024
size-512           19792  37168    512
size-256              81    105    256
size-192            1218   1280    192
Quoted 7 lines

size-64 31278 86907 64
size-128 5457 10380 128
size-32 594 784 32

Thank you

PS : I have no idea why the last lines (size-192, 64, 128, 32) are not ordered...

The size-32 and size-128 caches are created before any other cache, as the array_caches (arraycache_init) and kmem_list3's structure come from these cache.
Thus these caches are added to the cache_chain before other caches. And s_show just walks this chain and prints info for the caches.

Before l3 was converted into a pointer (per node slabs) we could intialize the caches in order as we knew that the arraycache_init will always fit in the first cache.

Thanks & Regards,
Alok

Quoted 8 lines

Eric
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#3 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to David S. Miller
Quoted 4 lines · David S. Miller

From: Eric Dumazet <[email protected]>
Date: Wed, 21 Dec 2005 10:11:51 +0100

Quoted 1 line

Could some of you post the result of the following command on your machines :

VAX KA650 (simulated), 4k pages (hw-size is 512 Bytes, though), L1_CACHE_BYTES=32

# grep "size-" /proc/slabinfo |grep -v DMA|cut -c1-40
size-131072            0      0 131072  
size-65536             0      0  65536  
size-32768             0      0  32768  
size-16384             0      0  16384  
size-8192              0      0   8192  
size-4096             21     21   4096  
size-2048             39     42   2060  
size-1024             18     21   1036  
size-512              70     70    524  
size-256               5     14    268  
size-192             722    722    204  
size-128             145    168    140  
size-96              382    396    108  
size-32             1040   1092     44  
size-64              338    350     76  

MfG, JBG

Signature · 4 lines
Jan-Benedict Glaw       [email protected]    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 für einen Freien Staat voll Freier Bürger"  | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
#5 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Eric Dumazet
Quoted 8 lines · Eric Dumazet

(x86_64 : PAGE_SIZE = 4096, L1_CACHE_BYTES = 64)

On my machines, I can say that the 32 and 192 sizes could be avoided in favor in spending less cpu cycles in __find_general_cachep()

Could some of you post the result of the following command on your machines :

# grep "size-" /proc/slabinfo |grep -v DMA|cut -c1-40
size-131072            0      0 131072
size-65536             3      3  65536
size-32768             0      0  32768
size-16384             3      3  16384
size-8192             28     28   8192
size-4096            184    184   4096
size-2048            272    272   2048
size-1024            300    300   1024
size-512             275    376    512
size-256             717    720    256
size-192            1120   1220    192

size-64 7720 8568 64
size-128 45019 65830 128
size-32 1627 3333 32

amd64 up

Ed Tomlinson

#6 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 16 lines
Quoted 5 lines

(x86_64 : PAGE_SIZE = 4096, L1_CACHE_BYTES = 64)
On my machines, I can say that the 32 and 192 sizes could be avoided in favor in spending less cpu cycles in __find_general_cachep()
Could some of you post the result of the following command on your machines :

# grep "size-" /proc/slabinfo |grep -v DMA|cut -c1-40
size-131072            0      0 131072
size-65536             3      3  65536
size-32768             0      0  32768
size-16384             3      3  16384
size-8192             28     28   8192
size-4096            184    184   4096
size-2048            272    272   2048
size-1024            300    300   1024
size-512             275    376    512
size-256             717    720    256
size-192            1120   1220    192
Quoted 3 lines

size-64 7720 8568 64
size-128 45019 65830 128
size-32 1627 3333 32

size-131072            0      0 131072
size-65536             0      0  65536
size-32768            20     20  32768
size-16384             8      9  16384
size-8192             37     38   8192
size-4096            269    269   4096
size-2048            793    910   2048
size-1024            564    608   1024
size-512             702    856    512
size-256            1485   4005    256
size-128            1209   1350    128
size-64             2858   3363     64
size-32             1538   2714     64

Intel(R) Xeon(TM) MP CPU 3.00GHz
address sizes : 40 bits physical, 48 bits virtual

Folkert van Heusden

- --
Try MultiTail! Multiple windows with logfiles, filtered with regular expressions, colored output, etc. etc. www.vanheusden.com/multitail/
- ---------------------------------------------------------------------- Get your PGP/GPG key signed at www.biglumber.com!
- ----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iIMEARECAEMFAkOpVq48Gmh0dHA6Ly93d3cudmFuaGV1c2Rlbi5jb20vZGF0YS1z aWduaW5nLXdpdGgtcGdwLXBvbGljeS5odG1sAAoJEDAZDowfKNiuUUEAnR9DJq5M x+Bj1R+djzCli3bFrJXKAJ9OmCx9FKDaGl6PocRwCZSKURerPA== =vQhF
-----END PGP SIGNATURE-----

#7 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 15 lines · Folkert van Heusden

size-131072            0      0 131072
size-65536             0      0  65536
size-32768            20     20  32768
size-16384             8      9  16384
size-8192             37     38   8192
size-4096            269    269   4096
size-2048            793    910   2048
size-1024            564    608   1024
size-512             702    856    512
size-256            1485   4005    256
size-128            1209   1350    128
size-64             2858   3363     64
size-32             1538   2714     64
Quoted 5 lines

Intel(R) Xeon(TM) MP CPU 3.00GHz
address sizes : 40 bits physical, 48 bits virtual

Folkert van Heusden

Hi Folkert

Your results are interesting : size-32 seems to use objects of size 64 !

Quoted 1 line

size-32 1538 2714 64 <<HERE>>

So I guess that size-32 cache could be avoided at least for EMT (I take you run a 64 bits kernel ?)

Eric

#8 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 16 lines
Quoted 13 lines
size-131072            0      0 131072
size-65536             0      0  65536
size-32768            20     20  32768
size-16384             8      9  16384
size-8192             37     38   8192
size-4096            269    269   4096
size-2048            793    910   2048
size-1024            564    608   1024
size-512             702    856    512
size-256            1485   4005    256
size-128            1209   1350    128
size-64             2858   3363     64
size-32             1538   2714     64
Quoted 2 lines

Intel(R) Xeon(TM) MP CPU 3.00GHz
address sizes : 40 bits physical, 48 bits virtual

Quoted 4 lines

Your results are interesting : size-32 seems to use objects of size 64 !

Quoted 1 line

size-32 1538 2714 64 <<HERE>>

So I guess that size-32 cache could be avoided at least for EMT (I take you run a 64 bits kernel ?)

I think I do yes:
Linux xxxxx 2.4.21-37.EL #1 SMP Wed Sep 7 13:32:18 EDT 2005 x86_64 x86_64 x86_64 GNU/Linux It is a redhat 4 x64 system.
Also from /proc/cpuinfo:
address sizes : 40 bits physical, 48 bits virtual

Folkert van Heusden

- --
Try MultiTail! Multiple windows with logfiles, filtered with regular expressions, colored output, etc. etc. www.vanheusden.com/multitail/
- ---------------------------------------------------------------------- Get your PGP/GPG key signed at www.biglumber.com!
- ----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iIMEARECAEMFAkOpYf08Gmh0dHA6Ly93d3cudmFuaGV1c2Rlbi5jb20vZGF0YS1z aWduaW5nLXdpdGgtcGdwLXBvbGljeS5odG1sAAoJEDAZDowfKNiugqYAoJWSoI9M O1sYrhWfFCoyTWweGN29AKCfPy46A1XHYC598IN4TXRSV2u6QA== =xMjS
-----END PGP SIGNATURE-----

#9 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 8 lines · Folkert van Heusden
Quoted 4 lines

Your results are interesting : size-32 seems to use objects of size 64 !

Quoted 1 line

size-32 1538 2714 64 <<HERE>>

So I guess that size-32 cache could be avoided at least for EMT (I take you run a 64 bits kernel ?)

I think I do yes:
Linux xxxxx 2.4.21-37.EL #1 SMP Wed Sep 7 13:32:18 EDT 2005 x86_64 x86_64 x86_64 GNU/Linux It is a redhat 4 x64 system.

Looks more like RHEL3 judging from the kernel version.

Dave

#10 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

Your results are interesting : size-32 seems to use objects of size 64 !

Quoted 1 line

size-32 1538 2714 64 <<HERE>>

So I guess that size-32 cache could be avoided at least for EMT (I take you run a 64 bits kernel ?)

I think I do yes:
Linux xxxxx 2.4.21-37.EL #1 SMP Wed Sep 7 13:32:18 EDT 2005 x86_64 x86_64 x86_64 GNU/Linux It is a redhat 4 x64 system.

Looks more like RHEL3 judging from the kernel version.

Ehr yes, you're totally right.

Folkert van Heusden

Signature · 6 lines
Try MultiTail! Multiple windows with logfiles, filtered with regular
expressions, colored output, etc. etc. www.vanheusden.com/multitail/
----------------------------------------------------------------------
Get your PGP/GPG key signed at www.biglumber.com!
----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
#11 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Eric Dumazet
Quoted 23 lines · Eric Dumazet

I wonder if the 32 and 192 bytes caches are worth to be declared in include/linux/kmalloc_sizes.h, at least on x86_64

(x86_64 : PAGE_SIZE = 4096, L1_CACHE_BYTES = 64)

On my machines, I can say that the 32 and 192 sizes could be avoided in favor in spending less cpu cycles in __find_general_cachep()

Could some of you post the result of the following command on your machines :

# grep "size-" /proc/slabinfo |grep -v DMA|cut -c1-40
size-131072            0      0 131072
size-65536             0      0  65536
size-32768             2      2  32768
size-16384             0      0  16384
size-8192             13     13   8192
size-4096            161    161   4096
size-2048          40564  42976   2048
size-1024            681    800   1024
size-512           19792  37168    512
size-256              81    105    256
size-192            1218   1280    192
Quoted 3 lines

size-64 31278 86907 64
size-128 5457 10380 128
size-32 594 784 32

# grep "size-" /proc/slabinfo |grep -v DMA|cut -c1-40
size-131072            0      0 131072
size-65536             0      0  65536
size-32768             1      1  32768
size-16384             0      0  16384
size-8192            253    253   8192
size-4096             89     89   4096
size-2048            248    248   2048
size-1024            312    312   1024
size-512             545    648    512
size-256             213    270    256
size-128            5642   5642    128
size-64             1025   1586     64
size-32             2262   7854     32
#12 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 28 lines · Denis Vlasenko
Quoted 23 lines · Eric Dumazet

I wonder if the 32 and 192 bytes caches are worth to be declared in include/linux/kmalloc_sizes.h, at least on x86_64

(x86_64 : PAGE_SIZE = 4096, L1_CACHE_BYTES = 64)

On my machines, I can say that the 32 and 192 sizes could be avoided in favor in spending less cpu cycles in __find_general_cachep()

Could some of you post the result of the following command on your machines :

# grep "size-" /proc/slabinfo |grep -v DMA|cut -c1-40
size-131072            0      0 131072
size-65536             0      0  65536
size-32768             2      2  32768
size-16384             0      0  16384
size-8192             13     13   8192
size-4096            161    161   4096
size-2048          40564  42976   2048
size-1024            681    800   1024
size-512           19792  37168    512
size-256              81    105    256
size-192            1218   1280    192
Quoted 3 lines

size-64 31278 86907 64
size-128 5457 10380 128
size-32 594 784 32

Quoted 14 lines
# grep "size-" /proc/slabinfo |grep -v DMA|cut -c1-40
size-131072            0      0 131072
size-65536             0      0  65536
size-32768             1      1  32768
size-16384             0      0  16384
size-8192            253    253   8192
size-4096             89     89   4096
size-2048            248    248   2048
size-1024            312    312   1024
size-512             545    648    512
size-256             213    270    256
size-128            5642   5642    128
size-64             1025   1586     64
size-32             2262   7854     32

Wow... I overlooked that you are requesting data from x86_64 boxes. Mine is not, it's i386...
--
vda

#13 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Am Mi 28.12.2005 09:54 schrieb Denis Vlasenko <[email protected]>:

Quoted 15 lines
Quoted 6 lines
# grep "size-" /proc/slabinfo |grep -v DMA|cut -c1-40
size-131072 0 0 131072
size-65536 0 0 65536
size-32768 1 1 32768
size-16384 0 0 16384
size-8192 253 253 8192
Quoted 8 lines
size-4096 89 89 4096
size-2048 248 248 2048
size-1024 312 312 1024
size-512 545 648 512
size-256 213 270 256
size-128 5642 5642 128
size-64 1025 1586 64
size-32 2262 7854 32
Quoted 2 lines

Wow... I overlooked that you are requesting data from x86_64 boxes. Mine is not, it's i386...

This whole discussion is pointless anyways because most kmallocs are constant
sized and with a constant sized kmalloc the slab is selected at compile time.

What would be more interesting would be to redo the complete kmalloc slab list.

I remember the original slab paper from Bonwick actually mentioned that power of
two slabs are the worst choice for a malloc - but for some reason Linux chose them
anyways. That would require a lot of measurements in different workloads on the
actual kmalloc sizes and then select a good list, but could ultimately safe
a lot of memory (ok not that much anymore because the memory intensive allocations should all have their own caches, but at least some)

Most likely the best list is different for 32bit and 64bit too.

Note that just looking at slabinfo is not enough for this - you need the original
sizes as passed to kmalloc, not the rounded values reported there. Should be probably not too hard to hack a simple monitoring script up for that
in systemtap to generate the data.

-Andi

#14 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 39 lines · Andreas Kleen

Am Mi 28.12.2005 09:54 schrieb Denis Vlasenko <[email protected]>:

Quoted 15 lines
Quoted 6 lines
# grep "size-" /proc/slabinfo |grep -v DMA|cut -c1-40
size-131072 0 0 131072
size-65536 0 0 65536
size-32768 1 1 32768
size-16384 0 0 16384
size-8192 253 253 8192
Quoted 8 lines
size-4096 89 89 4096
size-2048 248 248 2048
size-1024 312 312 1024
size-512 545 648 512
size-256 213 270 256
size-128 5642 5642 128
size-64 1025 1586 64
size-32 2262 7854 32
Quoted 2 lines

Wow... I overlooked that you are requesting data from x86_64 boxes. Mine is not, it's i386...

This whole discussion is pointless anyways because most kmallocs are constant
sized and with a constant sized kmalloc the slab is selected at compile time.

What would be more interesting would be to redo the complete kmalloc slab list.

I remember the original slab paper from Bonwick actually mentioned that power of
two slabs are the worst choice for a malloc - but for some reason Linux chose them
anyways. That would require a lot of measurements in different workloads on the
actual kmalloc sizes and then select a good list, but could ultimately safe
a lot of memory (ok not that much anymore because the memory intensive allocations should all have their own caches, but at least some)

Quoted 8 lines

Most likely the best list is different for 32bit and 64bit too.

Note that just looking at slabinfo is not enough for this - you need the original
sizes as passed to kmalloc, not the rounded values reported there. Should be probably not too hard to hack a simple monitoring script up for that
in systemtap to generate the data.

Something like this:

http://lwn.net/Articles/124374/

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#15 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 3 lines · Matt Mackall

Something like this:

http://lwn.net/Articles/124374/

Nice toy. Variant attached that works on 2.6.15rc7
- ->cs_size compile error fixed
- inlines kstrdup and kzalloc.
Otherwise these functions dominate the profile.

Dave

/proc/kmalloc allocation tracing

 tiny-mpm/fs/proc/proc_misc.c  |   21 ++++
 tiny-mpm/include/linux/slab.h |   19 ++++
 tiny-mpm/init/Kconfig         |    7 +
 tiny-mpm/mm/Makefile          |    2 
 tiny-mpm/mm/kmallocacct.c     |  182 ++++++++++++++++++++++++++++++++++++++++++
 tiny-mpm/mm/slab.c            |    7 +
 6 files changed, 237 insertions(+), 1 deletion(-)
init/Kconfig +7 -0
Index: tiny/init/Kconfig
===================================================================
@@ -315,6 +315,13 @@ config BUG
           option for embedded systems with no facilities for reporting errors.
           Just say Y.
 
+config KMALLOC_ACCOUNTING
+	default n
+	bool "Enabled accounting of kmalloc/kfree allocations"
+	help
+	  This option records kmalloc and kfree activity and reports it via
+	  /proc/kmalloc.
+
 config BASE_FULL
 	default y
 	bool "Enable full-sized data structures for core" if EMBEDDED
mm/slab.c +7 -1
Index: tiny/mm/slab.c
===================================================================
@@ -2911,6 +2911,8 @@ EXPORT_SYMBOL(kmalloc_node);
 void *__kmalloc(size_t size, unsigned int __nocast flags)
 {
 	kmem_cache_t *cachep;
+	struct cache_sizes *csizep = malloc_sizes;
+	void *a;
 
 	/* If you want to save a few bytes .text space: replace
 	 * __ with kmem_.
@@ -2920,7 +2921,9 @@ void *__kmalloc(size_t size, unsigned in
 	cachep = __find_general_cachep(size, flags);
 	if (unlikely(cachep == NULL))
 		return NULL;
-	return __cache_alloc(cachep, flags);
+	a = __cache_alloc(cachep, flags);
+	kmalloc_account(a, csizep->cs_size, size);
+	return a;
 }
 EXPORT_SYMBOL(__kmalloc);
 
@@ -3020,6 +3023,8 @@ void kfree(const void *objp)
 	kmem_cache_t *c;
 	unsigned long flags;
 
+	kfree_account(objp, ksize(objp));
+
 	if (unlikely(!objp))
 		return;
 	local_irq_save(flags);
mm/kmallocacct.c new file +182 -0

182 lines not on this page · raw message

mm/Makefile +1 -0
Index: tiny/mm/Makefile
===================================================================
@@ -12,6 +12,7 @@ obj-y			:= bootmem.o filemap.o mempool.o
 			   readahead.o slab.o swap.o truncate.o vmscan.o \
 			   prio_tree.o $(mmu-y)
 
+obj-$(CONFIG_KMALLOC_ACCOUNTING) += kmallocacct.o
 obj-$(CONFIG_SWAP)	+= page_io.o swap_state.o swapfile.o thrash.o
 obj-$(CONFIG_HUGETLBFS)	+= hugetlb.o
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
include/linux/slab.h +19 -0
Index: tiny/include/linux/slab.h
===================================================================
@@ -53,6 +53,23 @@ typedef struct kmem_cache_s kmem_cache_t
 #define SLAB_CTOR_ATOMIC	0x002UL		/* tell constructor it can't sleep */
 #define	SLAB_CTOR_VERIFY	0x004UL		/* tell constructor it's a verify call */
 
+#ifdef CONFIG_KMALLOC_ACCOUNTING
+void __kmalloc_account(const void *, const void *, int, int);
+
+static void inline kmalloc_account(const void *addr, int size, int req)
+{
+	__kmalloc_account(__builtin_return_address(0), addr, size, req);
+}
+
+static void inline kfree_account(const void *addr, int size)
+{
+	__kmalloc_account(__builtin_return_address(0), addr, size, -1);
+}
+#else
+#define kmalloc_account(a, b, c)
+#define kfree_account(a, b)
+#endif
+
 /* prototypes */
 extern void __init kmem_cache_init(void);
 
@@ -78,6 +95,7 @@ extern void *__kmalloc(size_t, unsigned 
 
 static inline void *kmalloc(size_t size, unsigned int __nocast flags)
 {
+#ifndef CONFIG_KMALLOC_ACCOUNTING
 	if (__builtin_constant_p(size)) {
 		int i = 0;
 #define CACHE(x) \
@@ -96,6 +114,7 @@ found:
 			malloc_sizes[i].cs_dmacachep :
 			malloc_sizes[i].cs_cachep, flags);
 	}
+#endif
 	return __kmalloc(size, flags);
 }
 
fs/proc/proc_misc.c +21 -0
Index: tiny/fs/proc/proc_misc.c
===================================================================
@@ -337,6 +337,24 @@ static struct file_operations proc_slabi
 	.release	= seq_release,
 };
 
+#ifdef CONFIG_KMALLOC_ACCOUNTING
+
+extern struct seq_operations kmalloc_account_op;
+
+static int kmalloc_account_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &kmalloc_account_op);
+}
+
+static struct file_operations proc_kmalloc_account_operations = {
+	.open		= kmalloc_account_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= seq_release,
+};
+
+#endif
+
 static int show_stat(struct seq_file *p, void *v)
 {
 	int i;
@@ -601,6 +619,9 @@ void __init proc_misc_init(void)
 	create_seq_entry("stat", 0, &proc_stat_operations);
 	create_seq_entry("interrupts", 0, &proc_interrupts_operations);
 	create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
+#ifdef CONFIG_KMALLOC_ACCOUNTING
+	create_seq_entry("kmalloc",S_IRUGO,&proc_kmalloc_account_operations);
+#endif
 	create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations);
 	create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations);
 	create_seq_entry("zoneinfo",S_IRUGO, &proc_zoneinfo_file_operations);
mm/slab.c renamed from mm/slab.c~ +0 -14
@@ -3045,20 +3045,6 @@ void kmem_cache_free(kmem_cache_t *cache
 EXPORT_SYMBOL(kmem_cache_free);
 
 /**
- * kzalloc - allocate memory. The memory is set to zero.
- * @size: how many bytes of memory are required.
- * @flags: the type of memory to allocate.
- */
-void *kzalloc(size_t size, gfp_t flags)
-{
-	void *ret = kmalloc(size, flags);
-	if (ret)
-		memset(ret, 0, size);
-	return ret;
-}
-EXPORT_SYMBOL(kzalloc);
-
-/**
  * kfree - free previously allocated memory
  * @objp: pointer returned by kmalloc.
  *
include/linux/slab.h renamed from include/linux/slab.h~ +7 -1
@@ -118,7 +118,13 @@ found:
 	return __kmalloc(size, flags);
 }
 
-extern void *kzalloc(size_t, gfp_t);
+static inline void *kzalloc(size_t size, gfp_t flags)
+{
+	void *ret = kmalloc(size, flags);
+	if (ret)
+		memset(ret, 0, size);
+	return ret;
+}
 
 /**
  * kcalloc - allocate memory for an array. The memory is set to zero.
include/linux/slab.h renamed from include/linux/slab.h~ +21 -0
@@ -126,6 +126,27 @@ static inline void *kzalloc(size_t size,
 	return ret;
 }
 
+/*
+ * kstrdup - allocate space for and copy an existing string
+ *
+ * @s: the string to duplicate
+ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
+ */
+static inline char *kstrdup(const char *s, gfp_t gfp)
+{
+	size_t len;
+	char *buf;
+
+	if (!s)
+		return NULL;
+
+	len = strlen(s) + 1;
+	buf = kmalloc(len, gfp);
+	if (buf)
+		memcpy(buf, s, len);
+	return buf;
+}
+
 /**
  * kcalloc - allocate memory for an array. The memory is set to zero.
  * @n: number of elements.
mm/slab.c renamed from mm/slab.c~ +0 -22
@@ -3669,25 +3669,3 @@ unsigned int ksize(const void *objp)
 	return obj_reallen(page_get_cache(virt_to_page(objp)));
 }
 
-
-/*
- * kstrdup - allocate space for and copy an existing string
- *
- * @s: the string to duplicate
- * @gfp: the GFP mask used in the kmalloc() call when allocating memory
- */
-char *kstrdup(const char *s, gfp_t gfp)
-{
-	size_t len;
-	char *buf;
-
-	if (!s)
-		return NULL;
-
-	len = strlen(s) + 1;
-	buf = kmalloc(len, gfp);
-	if (buf)
-		memcpy(buf, s, len);
-	return buf;
-}
-EXPORT_SYMBOL(kstrdup);
include/linux/string.h renamed from include/linux/string.h~ +0 -2
@@ -88,8 +88,6 @@ extern int memcmp(const void *,const voi
 extern void * memchr(const void *,int,__kernel_size_t);
 #endif
 
-extern char *kstrdup(const char *s, gfp_t gfp);
-
 #ifdef __cplusplus
 }
 #endif
#21 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Matt Mackall
Quoted 4 lines

Something like this:

http://lwn.net/Articles/124374/

One thing that really sticks out like a sore thumb is soft_cursor() That thing gets called a *lot*, and every time it does a kmalloc/free pair that 99.9% of the time is going to be the same size alloc as it was the last time. This patch makes that alloc persistent (and does a realloc if the size changes).
The only time it should change is if the font/resolution changes I think.

Boot tested with vesafb & fbconsole, which had the desired effect. With this patch, it almost falls off the profile.

drivers/video/console/softcursor.c renamed from drivers/video/console/softcursor.c~ +12 -5
@@ -23,7 +23,9 @@ int soft_cursor(struct fb_info *info, st
 	unsigned int buf_align = info->pixmap.buf_align - 1;
 	unsigned int i, size, dsize, s_pitch, d_pitch;
 	struct fb_image *image;
-	u8 *dst, *src;
+	u8 *dst;
+	static u8 *src=NULL;
+	static int allocsize=0;
 
 	if (info->state != FBINFO_STATE_RUNNING)
 		return 0;
@@ -31,9 +33,15 @@ int soft_cursor(struct fb_info *info, st
 	s_pitch = (cursor->image.width + 7) >> 3;
 	dsize = s_pitch * cursor->image.height;
 
-	src = kmalloc(dsize + sizeof(struct fb_image), GFP_ATOMIC);
-	if (!src)
-		return -ENOMEM;
+	if (dsize + sizeof(struct fb_image) != allocsize) {
+		if (src != NULL)
+			kfree(src);
+		allocsize = dsize + sizeof(struct fb_image);
+
+		src = kmalloc(allocsize, GFP_ATOMIC);
+		if (!src)
+			return -ENOMEM;
+	}
 
 	image = (struct fb_image *) (src + dsize);
 	*image = cursor->image;
@@ -61,7 +69,6 @@ int soft_cursor(struct fb_info *info, st
 	fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height);
 	image->data = dst;
 	info->fbops->fb_imageblit(info, image);
-	kfree(src);
 	return 0;
 }
 
#22 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 11 lines · Dave Jones (on Wed, 28 Dec 2005 20:29:15 -0500) wrote:
Quoted 4 lines

Something like this:

http://lwn.net/Articles/124374/

One thing that really sticks out like a sore thumb is soft_cursor() That thing gets called a *lot*, and every time it does a kmalloc/free pair that 99.9% of the time is going to be the same size alloc as it was the last time. This patch makes that alloc persistent (and does a realloc if the size changes).
The only time it should change is if the font/resolution changes I think.

Can soft_cursor() be called from multiple processes at the same time, in particular with dual head systems? If so then a static variable is not going to work.

#23 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 13 lines · Keith Owens
Quoted 11 lines · Dave Jones (on Wed, 28 Dec 2005 20:29:15 -0500) wrote:
Quoted 4 lines

Something like this:

http://lwn.net/Articles/124374/

One thing that really sticks out like a sore thumb is soft_cursor() That thing gets called a *lot*, and every time it does a kmalloc/free pair that 99.9% of the time is going to be the same size alloc as it was the last time. This patch makes that alloc persistent (and does a realloc if the size changes).
The only time it should change is if the font/resolution changes I think.

Quoted 3 lines

Can soft_cursor() be called from multiple processes at the same time, in particular with dual head systems? If so then a static variable is not going to work.

My dual-head system here displays a cloned image on the second screen, which seems to dtrt. I'm not sure how to make it show something different on the other head to test further.

Dave

#28 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Andreas Kleen

On Wed, 2005-12-28 at 18:57 +0100, Andreas Kleen wrote:
[...]

Quoted 20 lines

This whole discussion is pointless anyways because most kmallocs are constant
sized and with a constant sized kmalloc the slab is selected at compile time.

What would be more interesting would be to redo the complete kmalloc slab list.

I remember the original slab paper from Bonwick actually mentioned that power of
two slabs are the worst choice for a malloc - but for some reason Linux chose them
anyways. That would require a lot of measurements in different workloads on the
actual kmalloc sizes and then select a good list, but could ultimately safe
a lot of memory (ok not that much anymore because the memory intensive allocations should all have their own caches, but at least some)

Quoted 9 lines

Most likely the best list is different for 32bit and 64bit too.

Note that just looking at slabinfo is not enough for this - you need the original
sizes as passed to kmalloc, not the rounded values reported there. Should be probably not too hard to hack a simple monitoring script up for that
in systemtap to generate the data.

OK then, after reading this I figured there must be a way to dynamically allocate slab sizes based on the kmalloc constants. So I spent last night and some of this morning coming up with the below patch.

Right now it only works with i386, but I'm sure it can be hacked to work with all archs. At compile time it creates a table of sizes for all kmallocs (outside of slab.c and arch/i386/mm/init.c) that uses a constant declaration.

This table is then initialized in arch/i386/mm/init.c to use a cache that is either already created (like the mem_sizes array) or it creates a new cache of that size (L1 cached aligned), and then updates the pointers to use that cache.

Here's what was created on my test box:

cat /proc/slabinfo
[...]

dynamic_dma-1536       0      0   1536    5    2 : tunables   24   12    0 : slabdata      0      0      0
dynamic-1536           1      5   1536    5    2 : tunables   24   12    0 : slabdata      1      1      0
dynamic_dma-1280       0      0   1280    3    1 : tunables   24   12    0 : slabdata      0      0      0
dynamic-1280           6      6   1280    3    1 : tunables   24   12    0 : slabdata      2      2      0
dynamic_dma-2176       0      0   2176    3    2 : tunables   24   12    0 : slabdata      0      0      0
dynamic-2176           0      0   2176    3    2 : tunables   24   12    0 : slabdata      0      0      0
dynamic_dma-1152       0      0   1152    7    2 : tunables   24   12    0 : slabdata      0      0      0
dynamic-1152           0      0   1152    7    2 : tunables   24   12    0 : slabdata      0      0      0
dynamic_dma-1408       0      0   1408    5    2 : tunables   24   12    0 : slabdata      0      0      0
dynamic-1408           0      0   1408    5    2 : tunables   24   12    0 : slabdata      0      0      0
dynamic_dma-640        0      0    640    6    1 : tunables   54   27    0 : slabdata      0      0      0
dynamic-640            0      0    640    6    1 : tunables   54   27    0 : slabdata      0      0      0
dynamic_dma-768        0      0    768    5    1 : tunables   54   27    0 : slabdata      0      0      0
dynamic-768            0      0    768    5    1 : tunables   54   27    0 : slabdata      0      0      0
dynamic_dma-3200       0      0   3200    2    2 : tunables   24   12    0 : slabdata      0      0      0
dynamic-3200           8      8   3200    2    2 : tunables   24   12    0 : slabdata      4      4      0
dynamic_dma-896        0      0    896    4    1 : tunables   54   27    0 : slabdata      0      0      0
dynamic-896            9     12    896    4    1 : tunables   54   27    0 : slabdata      3      3      0
dynamic_dma-384        0      0    384   10    1 : tunables   54   27    0 : slabdata      0      0      0
dynamic-384           40     40    384   10    1 : tunables   54   27    0 : slabdata      4      4      0
size-131072(DMA)       0      0 131072    1   32 : tunables    8    4    0 : slabdata      0      0      0
size-131072            0      0 131072    1   32 : tunables    8    4    0 : slabdata      0      0      0
size-65536(DMA)        0      0  65536    1   16 : tunables    8    4    0 : slabdata      0      0      0
size-65536             1      1  65536    1   16 : tunables    8    4    0 : slabdata      1      1      0
size-32768(DMA)        0      0  32768    1    8 : tunables    8    4    0 : slabdata      0      0      0
size-32768             0      0  32768    1    8 : tunables    8    4    0 : slabdata      0      0      0
size-16384(DMA)        0      0  16384    1    4 : tunables    8    4    0 : slabdata      0      0      0
size-16384             0      0  16384    1    4 : tunables    8    4    0 : slabdata      0      0      0
size-8192(DMA)         0      0   8192    1    2 : tunables    8    4    0 : slabdata      0      0      0
size-8192             40     40   8192    1    2 : tunables    8    4    0 : slabdata     40     40      0
size-4096(DMA)         0      0   4096    1    1 : tunables   24   12    0 : slabdata      0      0      0
size-4096             34     34   4096    1    1 : tunables   24   12    0 : slabdata     34     34      0
size-2048(DMA)         0      0   2048    2    1 : tunables   24   12    0 : slabdata      0      0      0
size-2048            266    266   2048    2    1 : tunables   24   12    0 : slabdata    133    133      0
size-1024(DMA)         0      0   1024    4    1 : tunables   54   27    0 : slabdata      0      0      0
size-1024             24     24   1024    4    1 : tunables   54   27    0 : slabdata      6      6      0
size-512(DMA)          0      0    512    8    1 : tunables   54   27    0 : slabdata      0      0      0
size-512              90    112    512    8    1 : tunables   54   27    0 : slabdata     14     14      0
size-256(DMA)          0      0    256   15    1 : tunables  120   60    0 : slabdata      0      0      0
size-256             735    735    256   15    1 : tunables  120   60    0 : slabdata     49     49      0
size-128(DMA)          0      0    128   30    1 : tunables  120   60    0 : slabdata      0      0      0
size-128            2750   2760    128   30    1 : tunables  120   60    0 : slabdata     92     92      0
size-64(DMA)           0      0     64   59    1 : tunables  120   60    0 : slabdata      0      0      0
size-32(DMA)           0      0     32  113    1 : tunables  120   60    0 : slabdata      0      0      0
size-64              418    472     64   59    1 : tunables  120   60    0 : slabdata      8      8      0
size-32             1175   1243     32  113    1 : tunables  120   60    0 : slabdata     11     11      0

[...]

Not sure if this is worth looking further into, but it might actually be a way to use less memory. For example, the above 384 size with 40 objects cost only 4 4k pages, where as these same objects would be 40 512 objects (in size-512) costing 5 4k pages. Plus the 384 probably has ON_SLAB management where as the 512 does not.

Comments?

-- Steve

arch/i386/Kconfig +8 -0
Index: linux-2.6.15-rc7/arch/i386/Kconfig
===================================================================
@@ -173,6 +173,14 @@
 	depends on HPET_TIMER && RTC=y
 	default y
 
+config DYNAMIC_SLABS
+	bool "Dynamically create slabs for constant kmalloc"
+	default y
+	help
+	  This enables the creation of SLABS using information created at
+	  compile time.  Then on boot up, the slabs are created to fit
+	  more with what was asked for.
+
 config SMP
 	bool "Symmetric multi-processing support"
 	---help---
arch/i386/kernel/vmlinux.lds.S +16 -1
Index: linux-2.6.15-rc7/arch/i386/kernel/vmlinux.lds.S
===================================================================
@@ -68,6 +68,13 @@
 	*(.data.init_task)
   }
 
+#ifdef CONFIG_DYNAMIC_SLABS
+  . = ALIGN(16);		/* dynamic slab table */
+  __start____slab_addresses = .;
+  __slab_addresses : AT(ADDR(__slab_addresses) - LOAD_OFFSET) { *(__slab_addresses) }
+  __stop____slab_addresses = .;
+#endif
+
   /* will be freed after init */
   . = ALIGN(4096);		/* Init code and data */
   __init_begin = .;
@@ -107,6 +114,14 @@
   .altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
 	*(.altinstr_replacement)
   }
+#ifdef CONFIG_DYNAMIC_SLABS
+  . = ALIGN(16);		/* dynamic slab table */
+  __start____slab_preprocess = .;
+  __slab_preprocess : AT(ADDR(__slab_preprocess) - LOAD_OFFSET) { *(__slab_preprocess) }
+  __slab_process_ret : AT(ADDR(__slab_process_ret) - LOAD_OFFSET) { *(__slab_process_ret) }
+  __stop____slab_preprocess = .;
+#endif
+
   /* .exit.text is discard at runtime, not link time, to deal with references
      from .altinstructions and .eh_frame */
   .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) { *(.exit.text) }
@@ -119,7 +134,7 @@
   __per_cpu_start = .;
   .data.percpu  : AT(ADDR(.data.percpu) - LOAD_OFFSET) { *(.data.percpu) }
   __per_cpu_end = .;
-  . = ALIGN(4096);
+ . = ALIGN(4096);
   __init_end = .;
   /* freed after init ends here */
 	
arch/i386/mm/init.c +185 -0

194 lines not on this page · raw message

include/asm-i386/dynamic_slab.h new file +20 -0
Index: linux-2.6.15-rc7/include/asm-i386/dynamic_slab.h
===================================================================
@@ -0,0 +1,20 @@
+
+/*
+ * Included in slab.h
+ *
+ * @c    - cache pointer to return base on size
+ * @size - size of cache.
+ */
+__asm__ __volatile__ (
+	"jmp 2f\n"
+	".section __slab_preprocess,\"ax\"\n"
+	"movl %1,1f\n"
+	".previous\n"
+	".section __slab_addresses,\"aw\"\n"
+	".align 4\n"
+	"1:\n"
+	".long 0\n"
+	".previous\n"
+	"2:\n"
+	"movl 1b, %0\n"
+	: "=r"(c) : "i"(size));
include/linux/slab.h +9 -0
Index: linux-2.6.15-rc7/include/linux/slab.h
===================================================================
@@ -80,6 +80,15 @@
 {
 	if (__builtin_constant_p(size)) {
 		int i = 0;
+#if defined(CONFIG_DYNAMIC_SLABS) && !defined(MODULE) && !defined(DYNAMIC_SLABS_BOOTSTRAP)
+		{
+			struct cache_sizes *c;
+# include <asm/dynamic_slab.h>
+		return kmem_cache_alloc((flags & GFP_DMA) ?
+			c->cs_dmacachep :
+			c->cs_cachep, flags);
+		}
+#endif
 #define CACHE(x) \
 		if (size <= x) \
 			goto found; \
mm/slab.c +14 -0
Index: linux-2.6.15-rc7/mm/slab.c
===================================================================
@@ -86,6 +86,7 @@
  *	All object allocations for a node occur from node specific slab lists.
  */
 
+#define DYNAMIC_SLABS_BOOTSTRAP
 #include	<linux/config.h>
 #include	<linux/slab.h>
 #include	<linux/mm.h>
@@ -1165,6 +1166,19 @@
 	/* Done! */
 	g_cpucache_up = FULL;
 
+#ifdef CONFIG_DYNAMIC_SLABS
+	{
+		extern int dynamic_slab_init(void);
+		/*
+		 * Create the caches that will handle
+		 * kmallocs of constant sizes.
+		 */
+		dynamic_slab_init();
+	}
+#endif
+	/*
+	 */
+
 	/* Register a cpu startup notifier callback
 	 * that initializes ac_data for all new cpus
 	 */
#29 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 3 lines

OK then, after reading this I figured there must be a way to dynamically allocate slab sizes based on the kmalloc constants. So I spent last night and some of this morning coming up with the below patch.

The canonical slab theory is that constant allocations are for fixed objects. And if they are frequent they should be in theory kmem cache because in theory their object live times should be similar and clustering them together should give the best fragmentation advoidance.

So in theory longer term the dynamic kmallocs are more important because they cannot be handled like this - and these are not caught by your patch.

So I'm not sure you're optimizing the right thing here.

Perhaps a good evolution your patch would be to add some analysis of the callers and generate a nice compile time report that people can use as a guideline to convert kmalloc over the kmem_cache_alloc. But to do this really well would require dynamic data from runtime.

Given that I think a runtime patch is better. Ideally one that's easy to use with someone collecting data from users and then submitting a patch for a better new set of default slabs. Would need to be separate for 32bit and 64bit too.

I guess one could run a fancy dynamic optimization algorithm to find the best set of slabs from the data.

-Andi

#16 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Dave Jones
Quoted 10 lines · Dave Jones
Quoted 3 lines · Matt Mackall

Something like this:

http://lwn.net/Articles/124374/

Nice toy. Variant attached that works on 2.6.15rc7
- ->cs_size compile error fixed
- inlines kstrdup and kzalloc.
Otherwise these functions dominate the profile.

Attached is a variant that was refreshed against 2.6.15-rc7 and fixes the logical bug that your compile error fix made ;)

It should be cachep->objsize not csizep->cs_size.

-- Steve

/proc/kmalloc allocation tracing

 tiny-mpm/fs/proc/proc_misc.c  |   21 ++++
 tiny-mpm/include/linux/slab.h |   19 ++++
 tiny-mpm/init/Kconfig         |    7 +
 tiny-mpm/mm/Makefile          |    2 
 tiny-mpm/mm/kmallocacct.c     |  182 ++++++++++++++++++++++++++++++++++++++++++
 tiny-mpm/mm/slab.c            |    7 +
 6 files changed, 237 insertions(+), 1 deletion(-)
init/Kconfig +7 -0
Index: linux-2.6.15-rc7/init/Kconfig
===================================================================
@@ -328,6 +328,13 @@
           option for embedded systems with no facilities for reporting errors.
           Just say Y.
 
+config KMALLOC_ACCOUNTING
+	default n
+	bool "Enabled accounting of kmalloc/kfree allocations"
+	help
+	  This option records kmalloc and kfree activity and reports it via
+	  /proc/kmalloc.
+
 config BASE_FULL
 	default y
 	bool "Enable full-sized data structures for core" if EMBEDDED
mm/slab.c +6 -37

70 lines not on this page · raw message

mm/kmallocacct.c new file +182 -0

182 lines not on this page · raw message

mm/Makefile +1 -0
Index: linux-2.6.15-rc7/mm/Makefile
===================================================================
@@ -12,6 +12,7 @@
 			   readahead.o slab.o swap.o truncate.o vmscan.o \
 			   prio_tree.o $(mmu-y)
 
+obj-$(CONFIG_KMALLOC_ACCOUNTING) += kmallocacct.o
 obj-$(CONFIG_SWAP)	+= page_io.o swap_state.o swapfile.o thrash.o
 obj-$(CONFIG_HUGETLBFS)	+= hugetlb.o
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
include/linux/slab.h +47 -1

69 lines not on this page · raw message

fs/proc/proc_misc.c +21 -0
Index: linux-2.6.15-rc7/fs/proc/proc_misc.c
===================================================================
@@ -337,6 +337,24 @@
 	.release	= seq_release,
 };
 
+#ifdef CONFIG_KMALLOC_ACCOUNTING
+
+extern struct seq_operations kmalloc_account_op;
+
+static int kmalloc_account_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &kmalloc_account_op);
+}
+
+static struct file_operations proc_kmalloc_account_operations = {
+	.open		= kmalloc_account_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= seq_release,
+};
+
+#endif
+
 static int show_stat(struct seq_file *p, void *v)
 {
 	int i;
@@ -601,6 +619,9 @@
 	create_seq_entry("stat", 0, &proc_stat_operations);
 	create_seq_entry("interrupts", 0, &proc_interrupts_operations);
 	create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
+#ifdef CONFIG_KMALLOC_ACCOUNTING
+	create_seq_entry("kmalloc",S_IRUGO,&proc_kmalloc_account_operations);
+#endif
 	create_seq_entry("buddyinfo",S_IRUGO, &fragmentation_file_operations);
 	create_seq_entry("vmstat",S_IRUGO, &proc_vmstat_file_operations);
 	create_seq_entry("zoneinfo",S_IRUGO, &proc_zoneinfo_file_operations);
include/linux/string.h +0 -2
Index: linux-2.6.15-rc7/include/linux/string.h
===================================================================
@@ -88,8 +88,6 @@
 extern void * memchr(const void *,int,__kernel_size_t);
 #endif
 
-extern char *kstrdup(const char *s, gfp_t gfp);
-
 #ifdef __cplusplus
 }
 #endif
#26 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Matt Mackall

<snip>

Quoted 10 lines
Quoted 6 lines

Note that just looking at slabinfo is not enough for this - you need the original
sizes as passed to kmalloc, not the rounded values reported there. Should be probably not too hard to hack a simple monitoring script up for that
in systemtap to generate the data.

Something like this:

http://lwn.net/Articles/124374/

Written with a systemtap script:
http://sourceware.org/ml/systemtap/2005-q3/msg00550.html

#27 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 10 lines · Marcelo Tosatti

<snip>

Quoted 7 lines
Quoted 6 lines

Note that just looking at slabinfo is not enough for this - you need the original
sizes as passed to kmalloc, not the rounded values reported there. Should be probably not too hard to hack a simple monitoring script up for that
in systemtap to generate the data.

Quoted 6 lines
Quoted 3 lines

Something like this:

http://lwn.net/Articles/124374/

Written with a systemtap script:
http://sourceware.org/ml/systemtap/2005-q3/msg00550.html

I had actually written a similar script on my own before, but I found it was near completely unusable on a 4core Opteron system even under moderate load because systemtap bombed out when it needed more than one spin to take the lock of the shared hash table.

(it basically did if (!spin_trylock()) ... stop script; ...)

The problem was that the backtraces took so long that another CPU very often run into the locked lock.

Still with a stripped down script without backtraces had some interesting results. In particular my init was reading some file in /proc 10 times a second, allocating 4K (wtf did it do that?) and some other somewhat surprising results.

-Andi

#30 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Andreas Kleen
Quoted 3 lines · Andreas Kleen

I remember the original slab paper from Bonwick actually mentioned that power of two slabs are the worst choice for a malloc - but for some reason Linux chose them anyways.

Power of two sizes are bad because memory accesses tend to concentrate on the same cache lines but slab coloring should take care of that. So I don't think there's a problem with using power of twos for kmalloc() caches.

Pekka

#17 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Steven Rostedt

Hi,

Quoted 4 lines · Steven Rostedt

Attached is a variant that was refreshed against 2.6.15-rc7 and fixes the logical bug that your compile error fix made ;)

It should be cachep->objsize not csizep->cs_size.

Isn't there any other way to do this patch other than making kzalloc() and kstrdup() inline? I would like to see something like this in the mainline but making them inline is not acceptable because they increase kernel text a lot.

Pekka

#18 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 4 lines · Steven Rostedt
Quoted 4 lines

Attached is a variant that was refreshed against 2.6.15-rc7 and fixes the logical bug that your compile error fix made ;)

It should be cachep->objsize not csizep->cs_size.

Quoted 4 lines · Pekka Enberg

Isn't there any other way to do this patch other than making kzalloc() and kstrdup() inline? I would like to see something like this in the mainline but making them inline is not acceptable because they increase kernel text a lot.

Also, wouldn't it be better to track kmem_cache_alloc and kmem_cache_alloc_node instead?

Pekka

#20 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Pekka Enberg
Quoted 6 lines · Pekka Enberg

Hi,

Quoted 3 lines · Steven Rostedt

Attached is a variant that was refreshed against 2.6.15-rc7 and fixes the logical bug that your compile error fix made ;)

Quoted 6 lines
Quoted 1 line

It should be cachep->objsize not csizep->cs_size.

Isn't there any other way to do this patch other than making kzalloc() and kstrdup() inline? I would like to see something like this in the mainline but making them inline is not acceptable because they increase kernel text a lot.

Actually, yes. I was adding to this patch something to be more specific, and to either pass the EIP through the parameter or a __FILE__, __LINE__.

Using the following:

#ifdef CONFIG_KMALLOC_ACCOUNTING

# define __EIP__ , __builtin_return_address(0)
# define __DECLARE_EIP__ , void *eip
#else
# define __EIP__
# define __DECLARE_EIP__
#endif

#define kstrdup(s,g) __kstrdup(s, g __EIP__)
extern char *__kstrdup(const char *s, gfp_t g __DECLARE_EIP__);

Or a file line can be used:

# define __EIP__ , __FILE__, __LINE__
# define __DECLARE_EIP__ , char *file, int line

-- Steve

#19 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Pekka Enberg
Quoted 4 lines · Pekka Enberg

Also, wouldn't it be better to track kmem_cache_alloc and kmem_cache_alloc_node instead?

I believe they are very interested in when kmalloc and kfree are used, since those are the ones for the generic slabs. And even then, they are only profiling the ones that use a dynamic allocation. (the kmalloc and kfree of sizeof(x) is not profiled). This was brought up earlier in the thread.

-- Steve

#31 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Pekka Enberg
Quoted 9 lines · Pekka Enberg
Quoted 3 lines · Andreas Kleen

I remember the original slab paper from Bonwick actually mentioned that power of two slabs are the worst choice for a malloc - but for some reason Linux chose them anyways.

Power of two sizes are bad because memory accesses tend to concentrate on the same cache lines but slab coloring should take care of that. So I don't think there's a problem with using power of twos for kmalloc() caches.

There is - who tells you it's the best possible distribution of memory?

-Andi

#32 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 3 lines · Andreas Kleen
Quoted 3 lines
Quoted 3 lines

I remember the original slab paper from Bonwick actually mentioned that power of two slabs are the worst choice for a malloc - but for some reason Linux chose them anyways.

Quoted 4 lines · Pekka Enberg
Quoted 4 lines

Power of two sizes are bad because memory accesses tend to concentrate on the same cache lines but slab coloring should take care of that. So I don't think there's a problem with using power of twos for kmalloc() caches.

Quoted 1 line · Andi Kleen

There is - who tells you it's the best possible distribution of memory?

Maybe it's not. But that's besides the point. The specific problem Bonwick mentioned is related to cache line distribution and should be taken care of by slab coloring. Internal fragmentation is painful but the worst offenders can be fixed with kmem_cache_alloc(). So I really don't see the problem. On the other hand, I am not opposed to dynamic generic slabs if you can show a clear performance benefit from it. I just doubt you will.

Pekka

#33 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

Quoted 1 line · Pekka J Enberg

Maybe it's not. But that's besides the point.

It was my point. I don't know what your point was.

Quoted 6 lines

The specific problem Bonwick
mentioned is related to cache line distribution and should be taken care of by slab coloring. Internal fragmentation is painful but the worst offenders can be fixed with kmem_cache_alloc(). So I really don't see the problem. On the other hand, I am not opposed to dynamic generic slabs if you can show a clear performance benefit from it. I just doubt you will.

I wasn't proposing fully dynamic slabs, just a better default set of slabs based on real measurements instead of handwaving (like the power of two slabs seemed to have been generated). With separate sets for 32bit and 64bit.

Also the goal wouldn't be better performance, but just less waste of memory.

I suspect such a move could save much more memory on small systems than any of these "make fundamental debugging tools a CONFIG" patches ever.

-Andi

#24 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Dave Jones
Quoted 14 lines · Dave Jones
Quoted 13 lines · Keith Owens
Quoted 11 lines · Dave Jones (on Wed, 28 Dec 2005 20:29:15 -0500) wrote:
Quoted 4 lines

Something like this:

http://lwn.net/Articles/124374/

One thing that really sticks out like a sore thumb is soft_cursor() That thing gets called a *lot*, and every time it does a kmalloc/free pair that 99.9% of the time is going to be the same size alloc as it was the last time. This patch makes that alloc persistent (and does a realloc if the size changes).
The only time it should change is if the font/resolution changes I think.

Quoted 7 lines
Quoted 3 lines

Can soft_cursor() be called from multiple processes at the same time, in particular with dual head systems? If so then a static variable is not going to work.

My dual-head system here displays a cloned image on the second screen, which seems to dtrt. I'm not sure how to make it show something different on the other head to test further.

Few dualhead drivers actually support two different framebuffers, but the matrox G550 (and G400) drivers do. Compile one of those, make sure to configure dualhead support. After booting up, use "matroxset" to set the framebuffer to vga-connector mapping so that the two outputs actually show the different framebuffers.

Another way is to use several graphichs cards (AGP getting the first framebuffer and each PCI card getting others as the drivers load.)

Helge Hafting

#34 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Andi Kleen
Quoted 9 lines · Andi Kleen

I wasn't proposing fully dynamic slabs, just a better default set of slabs based on real measurements instead of handwaving (like the power of two slabs seemed to have been generated). With separate sets for 32bit and 64bit.

Also the goal wouldn't be better performance, but just less waste of memory.

I suspect such a move could save much more memory on small systems than any of these "make fundamental debugging tools a CONFIG" patches ever.

I misunderstood what you were proposing. Sorry. It makes sense to measure it.

Pekka

#35 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Andi Kleen
Quoted 7 lines · Andi Kleen

I wasn't proposing fully dynamic slabs, just a better default set of slabs based on real measurements instead of handwaving (like the power of two slabs seemed to have been generated). With separate sets for 32bit and 64bit.

Also the goal wouldn't be better performance, but just less waste of memory.

My fear would be that this leads to something like the gperf: a perfect distribution of slab caches - until any tiny detail changes. But maybe there is a different distribution that is "pretty good" for all configurations and better than powers of two.

Quoted 2 lines

I suspect such a move could save much more memory on small systems than any of these "make fundamental debugging tools a CONFIG" patches ever.

Unlikely. SLOB should be better than SLAB for those purposes, no matter how you arrange the slab caches.

Jörn

Signature · 4 lines
Fancy algorithms are slow when n is small, and n is usually small.
Fancy algorithms have big constants. Until you know that n is
frequently going to be big, don't get fancy.
-- Rob Pike
#25 lore raw

Re: [POLL] SLAB : Are the 32 and 192 bytes caches really usefull on x86_64 machines ?

In reply to Keith Owens
Quoted 13 lines · Keith Owens
Quoted 11 lines · Dave Jones (on Wed, 28 Dec 2005 20:29:15 -0500) wrote:
Quoted 4 lines

Something like this:

http://lwn.net/Articles/124374/

One thing that really sticks out like a sore thumb is soft_cursor() That thing gets called a *lot*, and every time it does a kmalloc/free pair that 99.9% of the time is going to be the same size alloc as it was the last time. This patch makes that alloc persistent (and does a realloc if the size changes).
The only time it should change is if the font/resolution changes I think.

Quoted 3 lines

Can soft_cursor() be called from multiple processes at the same time, in particular with dual head systems? If so then a static variable is not going to work.

I looked at this a little closer. If my understanding of the console/fb layers is correct, soft_cursor() is serialised by the console_sem in drivers/video/console/fbcon.c::fb_flashcursor()

Dave