Re: [PATCH 3/5] hugetlb: derive huge pages nodes allowed from task mempolicy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 25 Aug 2009, Lee Schermerhorn wrote:

> > > Index: linux-2.6.31-rc6-mmotm-090820-1918/mm/hugetlb.c
> > > ===================================================================
> > > --- linux-2.6.31-rc6-mmotm-090820-1918.orig/mm/hugetlb.c	2009-08-24 12:12:50.000000000 -0400
> > > +++ linux-2.6.31-rc6-mmotm-090820-1918/mm/hugetlb.c	2009-08-24 12:12:53.000000000 -0400
> > > @@ -1257,10 +1257,13 @@ static int adjust_pool_surplus(struct hs
> > >  static unsigned long set_max_huge_pages(struct hstate *h, unsigned long count)
> > >  {
> > >  	unsigned long min_count, ret;
> > > +	nodemask_t *nodes_allowed;
> > >  
> > >  	if (h->order >= MAX_ORDER)
> > >  		return h->max_huge_pages;
> > >  
> > 
> > Why can't you simply do this?
> > 
> > 	struct mempolicy *pol = NULL;
> > 	nodemask_t *nodes_allowed = &node_online_map;
> > 
> > 	local_irq_disable();
> > 	pol = current->mempolicy;
> > 	mpol_get(pol);
> > 	local_irq_enable();
> > 	if (pol) {
> > 		switch (pol->mode) {
> > 		case MPOL_BIND:
> > 		case MPOL_INTERLEAVE:
> > 			nodes_allowed = pol->v.nodes;
> > 			break;
> > 		case MPOL_PREFERRED:
> > 			... use NODEMASK_SCRATCH() ...
> > 		default:
> > 			BUG();
> > 		}
> > 	}
> > 	mpol_put(pol);
> > 
> > and then use nodes_allowed throughout set_max_huge_pages()?
> 
> 
> Well, I do use nodes_allowed [pointer] throughout set_max_huge_pages().

Yeah, the above code would all be in set_max_huge_pages() and 
huge_mpol_nodes_allowed() would be removed.

> NODEMASK_SCRATCH() didn't exist when I wrote this, and I can't be sure
> it will return a kmalloc()'d nodemask, which I need because a NULL
> nodemask pointer means "all online nodes" [really all nodes with memory,
> I suppose] and I need a pointer to kmalloc()'d nodemask to return from
> huge_mpol_nodes_allowed().  I want to keep the access to the internals
> of mempolicy in mempolicy.[ch], thus the call out to
> huge_mpol_nodes_allowed(), instead of open coding it.

Ok, so you could add a mempolicy.c helper function that returns
nodemask_t * and either points to mpol->v.nodes for most cases after 
getting a reference on mpol with mpol_get() or points to a dynamically 
allocated NODEMASK_ALLOC() on a nodemask created for MPOL_PREFERRED.

This works nicely because either way you still have a reference to mpol, 
so you'll need to call into a mpol_nodemask_free() function which can use 
the same switch statement:

	void mpol_nodemask_free(struct mempolicy *mpol,
				struct nodemask_t *nodes_allowed)
	{
		switch (mpol->mode) {
		case MPOL_PREFERRED:
			kfree(nodes_allowed);
			break;
		default:
			break;
		}
		mpol_put(mpol);
	}
--
To unsubscribe from this list: send the line "unsubscribe linux-numa" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]     [Devices]

  Powered by Linux