svn commit: r262739 - in stable/10/sys: kern sys vm

Gleb Smirnoff glebius at FreeBSD.org
Tue Mar 4 14:46:32 UTC 2014


Author: glebius
Date: Tue Mar  4 14:46:30 2014
New Revision: 262739
URL: http://svnweb.freebsd.org/changeset/base/262739

Log:
  Merge r261722, r261723, r261724, r261725 from head:
    several minor improvements for UMA_ZPCPU_ZONE zones.

Modified:
  stable/10/sys/kern/subr_counter.c
  stable/10/sys/kern/subr_pcpu.c
  stable/10/sys/sys/pcpu.h
  stable/10/sys/vm/uma.h
  stable/10/sys/vm/uma_core.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/subr_counter.c
==============================================================================
--- stable/10/sys/kern/subr_counter.c	Tue Mar  4 14:23:58 2014	(r262738)
+++ stable/10/sys/kern/subr_counter.c	Tue Mar  4 14:46:30 2014	(r262739)
@@ -41,8 +41,6 @@ __FBSDID("$FreeBSD$");
 #define IN_SUBR_COUNTER_C
 #include <sys/counter.h>
  
-static uma_zone_t uint64_pcpu_zone;
-
 void
 counter_u64_zero(counter_u64_t c)
 {
@@ -62,7 +60,7 @@ counter_u64_alloc(int flags)
 {
 	counter_u64_t r;
 
-	r = uma_zalloc(uint64_pcpu_zone, flags);
+	r = uma_zalloc(pcpu_zone_64, flags);
 	if (r != NULL)
 		counter_u64_zero(r);
 
@@ -73,7 +71,7 @@ void
 counter_u64_free(counter_u64_t c)
 {
 
-	uma_zfree(uint64_pcpu_zone, c);
+	uma_zfree(pcpu_zone_64, c);
 }
 
 int
@@ -96,12 +94,3 @@ sysctl_handle_counter_u64(SYSCTL_HANDLER
 
 	return (0);
 }
-
-static void
-counter_startup(void)
-{
-
-	uint64_pcpu_zone = uma_zcreate("uint64 pcpu", sizeof(uint64_t),
-	    NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_PCPU);
-}
-SYSINIT(counter, SI_SUB_KMEM, SI_ORDER_ANY, counter_startup, NULL);

Modified: stable/10/sys/kern/subr_pcpu.c
==============================================================================
--- stable/10/sys/kern/subr_pcpu.c	Tue Mar  4 14:23:58 2014	(r262738)
+++ stable/10/sys/kern/subr_pcpu.c	Tue Mar  4 14:46:30 2014	(r262739)
@@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/proc.h>
 #include <sys/smp.h>
 #include <sys/sx.h>
+#include <vm/uma.h>
 #include <ddb/ddb.h>
 
 static MALLOC_DEFINE(M_PCPU, "Per-cpu", "Per-cpu resource accouting.");
@@ -127,6 +128,30 @@ dpcpu_startup(void *dummy __unused)
 SYSINIT(dpcpu, SI_SUB_KLD, SI_ORDER_FIRST, dpcpu_startup, 0);
 
 /*
+ * UMA_PCPU_ZONE zones, that are available for all kernel
+ * consumers. Right now 64 bit zone is used for counter(9)
+ * and pointer zone is used by flowtable.
+ */
+
+uma_zone_t pcpu_zone_64;
+uma_zone_t pcpu_zone_ptr;
+
+static void
+pcpu_zones_startup(void)
+{
+
+	pcpu_zone_64 = uma_zcreate("64 pcpu", sizeof(uint64_t),
+	    NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_PCPU);
+
+	if (sizeof(uint64_t) == sizeof(void *))
+		pcpu_zone_ptr = pcpu_zone_64;
+	else
+		pcpu_zone_ptr = uma_zcreate("ptr pcpu", sizeof(void *),
+		    NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_PCPU);
+}
+SYSINIT(pcpu_zones, SI_SUB_KMEM, SI_ORDER_ANY, pcpu_zones_startup, NULL);
+
+/*
  * First-fit extent based allocator for allocating space in the per-cpu
  * region reserved for modules.  This is only intended for use by the
  * kernel linkers to place module linker sets.

Modified: stable/10/sys/sys/pcpu.h
==============================================================================
--- stable/10/sys/sys/pcpu.h	Tue Mar  4 14:23:58 2014	(r262738)
+++ stable/10/sys/sys/pcpu.h	Tue Mar  4 14:46:30 2014	(r262739)
@@ -210,6 +210,13 @@ zpcpu_get(void *base)
 	return ((char *)(base) + sizeof(struct pcpu) * curcpu);
 }
 
+static inline void *
+zpcpu_get_cpu(void *base, int cpu)
+{
+
+	return ((char *)(base) + sizeof(struct pcpu) * cpu);
+}
+
 /*
  * Machine dependent callouts.  cpu_pcpu_init() is responsible for
  * initializing machine dependent fields of struct pcpu, and

Modified: stable/10/sys/vm/uma.h
==============================================================================
--- stable/10/sys/vm/uma.h	Tue Mar  4 14:23:58 2014	(r262738)
+++ stable/10/sys/vm/uma.h	Tue Mar  4 14:46:30 2014	(r262739)
@@ -33,8 +33,8 @@
  *
 */
 
-#ifndef VM_UMA_H
-#define VM_UMA_H
+#ifndef _VM_UMA_H_
+#define _VM_UMA_H_
 
 #include <sys/param.h>		/* For NULL */
 #include <sys/malloc.h>		/* For M_* */
@@ -636,6 +636,12 @@ int uma_zone_exhausted(uma_zone_t zone);
 int uma_zone_exhausted_nolock(uma_zone_t zone);
 
 /*
+ * Common UMA_ZONE_PCPU zones.
+ */
+extern uma_zone_t pcpu_zone_64;
+extern uma_zone_t pcpu_zone_ptr;
+
+/*
  * Exported statistics structures to be used by user space monitoring tools.
  * Statistics stream consists of a uma_stream_header, followed by a series of
  * alternative uma_type_header and uma_type_stat structures.
@@ -683,4 +689,4 @@ struct uma_percpu_stat {
 	uint64_t	_ups_reserved[5];	/* Reserved. */
 };
 
-#endif
+#endif	/* _VM_UMA_H_ */

Modified: stable/10/sys/vm/uma_core.c
==============================================================================
--- stable/10/sys/vm/uma_core.c	Tue Mar  4 14:23:58 2014	(r262738)
+++ stable/10/sys/vm/uma_core.c	Tue Mar  4 14:46:30 2014	(r262739)
@@ -264,6 +264,7 @@ static uma_keg_t uma_kcreate(uma_zone_t 
     uma_fini fini, int align, uint32_t flags);
 static int zone_import(uma_zone_t zone, void **bucket, int max, int flags);
 static void zone_release(uma_zone_t zone, void **bucket, int cnt);
+static void uma_zero_item(void *item, uma_zone_t zone);
 
 void uma_print_zone(uma_zone_t);
 void uma_print_stats(void);
@@ -2167,7 +2168,7 @@ zalloc_start:
 		uma_dbg_alloc(zone, NULL, item);
 #endif
 		if (flags & M_ZERO)
-			bzero(item, zone->uz_size);
+			uma_zero_item(item, zone);
 		return (item);
 	}
 
@@ -2617,7 +2618,7 @@ zone_alloc_item(uma_zone_t zone, void *u
 	uma_dbg_alloc(zone, NULL, item);
 #endif
 	if (flags & M_ZERO)
-		bzero(item, zone->uz_size);
+		uma_zero_item(item, zone);
 
 	return (item);
 
@@ -3234,6 +3235,17 @@ uma_large_free(uma_slab_t slab)
 	zone_free_item(slabzone, slab, NULL, SKIP_NONE);
 }
 
+static void
+uma_zero_item(void *item, uma_zone_t zone)
+{
+
+	if (zone->uz_flags & UMA_ZONE_PCPU) {
+		for (int i = 0; i < mp_ncpus; i++)
+			bzero(zpcpu_get_cpu(item, i), zone->uz_size);
+	} else
+		bzero(item, zone->uz_size);
+}
+
 void
 uma_print_stats(void)
 {


More information about the svn-src-all mailing list