On Tue, Oct 28, 2014 at 16:49, David Gwynne wrote:
> when i shuffled the locking in pools around, page colouring was
> left behind.
> 
> page colouring is where you offset items within a page if you have
> enough slack space. the previous implementation simply incremented
> the colour so each new page got the next offset. i didnt do this
> because the page and its items are now initted outside the lock,
> so maintaining that curcolour iterator wasnt as easy.
> 
> this sidesteps the curcolor maintenance by just having each page
> randomly pick a colour when it's set up.
> 
> tests? ok?

So after all that we're back to this (but updated to apply since I
broke it)? ok, why not? I was trying to save us the trouble, but maybe
that was a bad idea.

ok with me.


> 
> Index: kern/subr_pool.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/subr_pool.c,v
> retrieving revision 1.163
> diff -u -p -r1.163 subr_pool.c
> --- kern/subr_pool.c  13 Oct 2014 00:12:51 -0000      1.163
> +++ kern/subr_pool.c  28 Oct 2014 03:05:50 -0000
> @@ -299,8 +299,7 @@ pool_init(struct pool *pp, size_t size,
> */
> space = POOL_INPGHDR(pp) ? pp->pr_phoffset : pp->pr_pgsize;
> space -= pp->pr_itemsperpage * pp->pr_size;
> -     pp->pr_maxcolor = (space / align) * align;
> -     pp->pr_curcolor = 0;
> +     pp->pr_maxcolors = (space / align) + 1;
> 
> pp->pr_nget = 0;
> pp->pr_nfail = 0;
> @@ -750,6 +749,8 @@ pool_p_alloc(struct pool *pp, int flags)
> 
> XSIMPLEQ_INIT(&ph->ph_itemlist);
> ph->ph_page = addr;
> +     ph->ph_colored = addr +
> +         arc4random_uniform(pp->pr_maxcolors) * pp->pr_align;
> ph->ph_nmissing = 0;
> arc4random_buf(&ph->ph_magic, sizeof(ph->ph_magic));
> #ifdef DIAGNOSTIC
> @@ -760,6 +761,7 @@ pool_p_alloc(struct pool *pp, int flags)
> CLR(ph->ph_magic, POOL_MAGICBIT);
> #endif /* DIAGNOSTIC */
> 
> +     addr = ph->ph_colored;
> n = pp->pr_itemsperpage;
> while (n--) {
> pi = (struct pool_item *)addr;
> @@ -996,8 +998,8 @@ pool_print_pagelist(struct pool_pagelist
> struct pool_item *pi;
> 
> LIST_FOREACH(ph, pl, ph_pagelist) {
> -             (*pr)("\t\tpage %p, nmissing %d\n",
> -                 ph->ph_page, ph->ph_nmissing);
> +             (*pr)("\t\tpage %p, color %p, nmissing %d\n",
> +                 ph->ph_page, ph->ph_colored, ph->ph_nmissing);
> XSIMPLEQ_FOREACH(pi, &ph->ph_itemlist, pi_list) {
> if (pi->pi_magic != POOL_IMAGIC(ph, pi)) {
> (*pr)("\t\t\titem %p, magic 0x%lx\n",
> @@ -1021,8 +1023,8 @@ pool_print1(struct pool *pp, const char
> modif++;
> }
> 
> -     (*pr)("POOL %s: size %u, align %u, roflags 0x%08x\n",
> -         pp->pr_wchan, pp->pr_size, pp->pr_align,
> +     (*pr)("POOL %s: size %u, align %u, maxcolors %u, roflags 0x%08x\n",
> +         pp->pr_wchan, pp->pr_size, pp->pr_align, pp->pr_maxcolors,
> pp->pr_roflags);
> (*pr)("\talloc %p\n", pp->pr_alloc);
> (*pr)("\tminitems %u, minpages %u, maxpages %u, npages %u\n",
> Index: sys/pool.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/pool.h,v
> retrieving revision 1.53
> diff -u -p -r1.53 pool.h
> --- sys/pool.h        22 Sep 2014 01:04:58 -0000      1.53
> +++ sys/pool.h        28 Oct 2014 03:05:50 -0000
> @@ -128,8 +128,7 @@ struct pool {
> RB_HEAD(phtree, pool_item_header)
> pr_phtree;
> 
> -     int             pr_maxcolor;    /* Cache colouring */
> -     int             pr_curcolor;
> +     u_int           pr_maxcolors;   /* Cache colouring */
> int           pr_phoffset;    /* Offset in page of page header */
> 
> /*

Reply via email to