public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrea Righi <righi.andrea@gmail.com>
To: Ryo Tsuruta <ryov@valinux.co.jp>
Cc: linux-kernel@vger.kernel.org, dm-devel@redhat.com,
	containers@lists.linux-foundation.org,
	virtualization@lists.linux-foundation.org,
	xen-devel@lists.xensource.com, agk@sourceware.org
Subject: Re: [PATCH 4/7] bio-cgroup: Split the cgroup memory subsystem into two parts
Date: Tue,  5 Aug 2008 12:25:33 +0200 (MEST)	[thread overview]
Message-ID: <48982A9D.2000803@gmail.com> (raw)
In-Reply-To: <20080804.175748.189722512.ryov@valinux.co.jp>

Ryo Tsuruta wrote:
> +static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
> +				gfp_t gfp_mask, enum charge_type ctype,
> +				struct mem_cgroup *memcg)
> +{
> +	struct page_cgroup *pc;
> +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
> +	struct mem_cgroup *mem;
> +	unsigned long flags;
> +	unsigned long nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
> +	struct mem_cgroup_per_zone *mz;
> +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
> +
> +	pc = kmem_cache_alloc(page_cgroup_cache, gfp_mask);
> +	if (unlikely(pc == NULL))
> +		goto err;
> +
> +	/*
> +	 * We always charge the cgroup the mm_struct belongs to.
> +	 * The mm_struct's mem_cgroup changes on task migration if the
> +	 * thread group leader migrates. It's possible that mm is not
> +	 * set, if so charge the init_mm (happens for pagecache usage).
> +	 */
> +	if (likely(!memcg)) {
> +		rcu_read_lock();
> +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
> +		mem = mem_cgroup_from_task(rcu_dereference(mm->owner));
> +		/*
> +		 * For every charge from the cgroup, increment reference count
> +		 */
> +		css_get(&mem->css);
> +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
> +		rcu_read_unlock();
> +	} else {
> +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
> +		mem = memcg;
> +		css_get(&memcg->css);
> +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
> +	}
> +
> +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
> +	while (res_counter_charge(&mem->res, PAGE_SIZE)) {
> +		if (!(gfp_mask & __GFP_WAIT))
> +			goto out;
> +
> +		if (try_to_free_mem_cgroup_pages(mem, gfp_mask))
> +			continue;
> +
> +		/*
> +		 * try_to_free_mem_cgroup_pages() might not give us a full
> +		 * picture of reclaim. Some pages are reclaimed and might be
> +		 * moved to swap cache or just unmapped from the cgroup.
> +		 * Check the limit again to see if the reclaim reduced the
> +		 * current usage of the cgroup before giving up
> +		 */
> +		if (res_counter_check_under_limit(&mem->res))
> +			continue;
> +
> +		if (!nr_retries--) {
> +			mem_cgroup_out_of_memory(mem, gfp_mask);
> +			goto out;
> +		}
> +	}
> +	pc->mem_cgroup = mem;
> +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */

you can remove some ifdefs doing:

#ifdef CONFIG_CGROUP_MEM_RES_CTLR
	if (likely(!memcg)) {
		rcu_read_lock();
		mem = mem_cgroup_from_task(rcu_dereference(mm->owner));
		/*
		 * For every charge from the cgroup, increment reference count
		 */
		css_get(&mem->css);
		rcu_read_unlock();
	} else {
		mem = memcg;
		css_get(&memcg->css);
	}
	while (res_counter_charge(&mem->res, PAGE_SIZE)) {
		if (!(gfp_mask & __GFP_WAIT))
			goto out;

		if (try_to_free_mem_cgroup_pages(mem, gfp_mask))
			continue;

		/*
		 * try_to_free_mem_cgroup_pages() might not give us a full
		 * picture of reclaim. Some pages are reclaimed and might be
		 * moved to swap cache or just unmapped from the cgroup.
		 * Check the limit again to see if the reclaim reduced the
		 * current usage of the cgroup before giving up
		 */
		if (res_counter_check_under_limit(&mem->res))
			continue;

		if (!nr_retries--) {
			mem_cgroup_out_of_memory(mem, gfp_mask);
			goto out;
		}
	}
	pc->mem_cgroup = mem;
#endif /* CONFIG_CGROUP_MEM_RES_CTLR */

  parent reply	other threads:[~2008-08-05 10:30 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-04  8:51 [PATCH 0/7] I/O bandwidth controller and BIO tracking Ryo Tsuruta
2008-08-04  8:52 ` [PATCH 1/7] dm-ioband: Patch of device-mapper driver Ryo Tsuruta
2008-08-04  8:52   ` [PATCH 2/7] dm-ioband: Documentation of design overview, installation, command reference and examples Ryo Tsuruta
2008-08-04  8:57     ` [PATCH 3/7] bio-cgroup: Introduction Ryo Tsuruta
2008-08-04  8:57       ` [PATCH 4/7] bio-cgroup: Split the cgroup memory subsystem into two parts Ryo Tsuruta
2008-08-04  8:59         ` [PATCH 5/7] bio-cgroup: Remove a lot of ifdefs Ryo Tsuruta
2008-08-04  9:00           ` [PATCH 6/7] bio-cgroup: Implement the bio-cgroup Ryo Tsuruta
2008-08-04  9:01             ` [PATCH 7/7] bio-cgroup: Add a cgroup support to dm-ioband Ryo Tsuruta
2008-08-08  7:10             ` [PATCH 6/7] bio-cgroup: Implement the bio-cgroup Takuya Yoshikawa
2008-08-08  8:30               ` Ryo Tsuruta
2008-08-08  9:42                 ` Takuya Yoshikawa
2008-08-08 11:41                   ` Ryo Tsuruta
2008-08-05 10:25         ` Andrea Righi [this message]
2008-08-05 10:35           ` [PATCH 4/7] bio-cgroup: Split the cgroup memory subsystem into two parts Hirokazu Takahashi
2008-08-06  7:54         ` KAMEZAWA Hiroyuki
2008-08-06 11:43           ` Hirokazu Takahashi
2008-08-06 13:45             ` kamezawa.hiroyu
2008-08-07  7:25               ` Hirokazu Takahashi
2008-08-07  8:21                 ` KAMEZAWA Hiroyuki
2008-08-07  8:45                   ` Hirokazu Takahashi
2008-08-04 17:20 ` Too many I/O controller patches Dave Hansen
2008-08-04 18:22   ` Andrea Righi
2008-08-04 19:02     ` Dave Hansen
2008-08-04 20:44       ` Andrea Righi
2008-08-04 20:50         ` Dave Hansen
2008-08-05  6:28           ` Hirokazu Takahashi
2008-08-05  5:55         ` Paul Menage
2008-08-05  6:03           ` Balbir Singh
2008-08-05  9:27           ` Andrea Righi
2008-08-05 16:25           ` Dave Hansen
2008-08-05  6:16         ` Hirokazu Takahashi
2008-08-05  9:31           ` Andrea Righi
2008-08-05 10:01             ` Hirokazu Takahashi
2008-08-05  2:50     ` Satoshi UCHIDA
2008-08-05  9:28       ` Andrea Righi
2008-08-05 13:17         ` Ryo Tsuruta
2008-08-05 16:20         ` Dave Hansen
2008-08-06  2:44           ` KAMEZAWA Hiroyuki
2008-08-06  3:30             ` Balbir Singh
2008-08-06  6:48             ` Hirokazu Takahashi
2008-08-05 12:01       ` Hirokazu Takahashi
2008-08-04 18:34   ` Balbir Singh
2008-08-04 20:42     ` Andrea Righi
2008-08-06  1:13   ` RFC: I/O bandwidth controller (was Re: Too many I/O controller patches) Fernando Luis Vázquez Cao
2008-08-06  6:18     ` RFC: I/O bandwidth controller Ryo Tsuruta
2008-08-06  6:41       ` Fernando Luis Vázquez Cao
2008-08-06 15:48         ` Dave Hansen
2008-08-07  4:38           ` Fernando Luis Vázquez Cao
2008-08-06 16:42     ` RFC: I/O bandwidth controller (was Re: Too many I/O controller patches) Balbir Singh
2008-08-06 18:00       ` Dave Hansen
2008-08-07  2:44       ` Fernando Luis Vázquez Cao
2008-08-07  3:01       ` Fernando Luis Vázquez Cao
2008-08-08 11:39         ` RFC: I/O bandwidth controller Hirokazu Takahashi
2008-08-12  5:35           ` Fernando Luis Vázquez Cao
2008-08-06 19:37     ` RFC: I/O bandwidth controller (was Re: Too many I/O controller patches) Naveen Gupta
2008-08-07  8:30       ` RFC: I/O bandwidth controller Hirokazu Takahashi
2008-08-07 13:17       ` RFC: I/O bandwidth controller (was Re: Too many I/O controller patches) Fernando Luis Vázquez Cao
2008-08-11 18:18         ` Naveen Gupta
2008-08-11 16:35           ` David Collier-Brown
2008-08-07  7:46     ` Andrea Righi
2008-08-07 13:59       ` Fernando Luis Vázquez Cao
2008-08-11 20:52         ` Andrea Righi
     [not found]           ` <loom.20080812T071504-212@post.gmane.org>
2008-08-12 11:10             ` RFC: I/O bandwidth controller Hirokazu Takahashi
2008-08-12 12:55               ` Andrea Righi
2008-08-12 13:07                 ` Andrea Righi
2008-08-12 13:54                   ` Fernando Luis Vázquez Cao
2008-08-12 15:03                     ` James.Smart
2008-08-12 21:00                       ` Andrea Righi
2008-08-12 20:44                     ` Andrea Righi
2008-08-13  7:47                       ` Dong-Jae Kang
2008-08-13 17:56                         ` Andrea Righi
2008-08-14 11:18                 ` David Collier-Brown
2008-08-12 13:15               ` Fernando Luis Vázquez Cao
2008-08-13  6:23               ` 강동재
2008-08-08  6:21     ` Hirokazu Takahashi
2008-08-08  7:20       ` Ryo Tsuruta
2008-08-08  8:10         ` Fernando Luis Vázquez Cao
2008-08-08 10:05           ` Ryo Tsuruta
2008-08-08 14:31       ` Hirokazu Takahashi
  -- strict thread matches above, loose matches on Subject: below --
2008-08-12 12:33 [PATCH 1/7] dm-ioband: Patch of device-mapper driver Ryo Tsuruta
2008-08-12 12:34 ` [PATCH 2/7] dm-ioband: Documentation of design overview, installation, command reference and examples Ryo Tsuruta
2008-08-12 12:34   ` [PATCH 3/7] bio-cgroup: Introduction Ryo Tsuruta
2008-08-12 12:35     ` [PATCH 4/7] bio-cgroup: Split the cgroup memory subsystem into two parts Ryo Tsuruta
2008-08-18  1:39       ` KAMEZAWA Hiroyuki
2008-08-19  3:28         ` Ryo Tsuruta
2008-08-19  4:01           ` Balbir Singh
2008-08-19 12:46             ` Hirokazu Takahashi
2008-08-19 13:48               ` Balbir Singh
2008-08-20  5:47                 ` Hirokazu Takahashi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48982A9D.2000803@gmail.com \
    --to=righi.andrea@gmail.com \
    --cc=agk@sourceware.org \
    --cc=containers@lists.linux-foundation.org \
    --cc=dm-devel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ryov@valinux.co.jp \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox