linux-next.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Rothwell <sfr@canb.auug.org.au>
To: Andrew Morton <akpm@linux-foundation.org>, Jens Axboe <axboe@kernel.dk>
Cc: Dan Schatzberg <schatzberg.dan@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux Next Mailing List <linux-next@vger.kernel.org>,
	Shakeel Butt <shakeelb@google.com>
Subject: linux-next: manual merge of the akpm-current tree with the block tree
Date: Thu, 18 Mar 2021 17:17:20 +1100	[thread overview]
Message-ID: <20210318171720.61a3f59c@canb.auug.org.au> (raw)

[-- Attachment #1: Type: text/plain, Size: 4726 bytes --]

Hi all,

Today's linux-next merge of the akpm-current tree got a conflict in:

  mm/memcontrol.c

between commit:

  06d69d4c8669 ("mm: Charge active memcg when no mm is set")

from the block tree and commit:

  674788258a66 ("memcg: charge before adding to swapcache on swapin")

from the akpm-current tree.

I fixed it up (I think - see below) and can carry the fix as necessary.
This is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc mm/memcontrol.c
index f05501669e29,668d1d7c2645..000000000000
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@@ -6691,65 -6549,73 +6550,80 @@@ out
   * @gfp_mask: reclaim mode
   *
   * Try to charge @page to the memcg that @mm belongs to, reclaiming
 - * pages according to @gfp_mask if necessary.
 + * pages according to @gfp_mask if necessary. if @mm is NULL, try to
 + * charge to the active memcg.
   *
+  * Do not use this for pages allocated for swapin.
+  *
   * Returns 0 on success. Otherwise, an error code is returned.
   */
  int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask)
  {
- 	unsigned int nr_pages = thp_nr_pages(page);
- 	struct mem_cgroup *memcg = NULL;
- 	int ret = 0;
+ 	struct mem_cgroup *memcg;
+ 	int ret;
  
  	if (mem_cgroup_disabled())
- 		goto out;
+ 		return 0;
  
- 	if (PageSwapCache(page)) {
- 		swp_entry_t ent = { .val = page_private(page), };
- 		unsigned short id;
 -	memcg = get_mem_cgroup_from_mm(mm);
++	if (!mm) {
++		memcg = get_mem_cgroup_from_current();
++		if (!memcg)
++			memcg = get_mem_cgroup_from_mm(current->mm);
++	} else {
++		memcg = get_mem_cgroup_from_mm(mm);
++	}
+ 	ret = __mem_cgroup_charge(page, memcg, gfp_mask);
+ 	css_put(&memcg->css);
  
- 		/*
- 		 * Every swap fault against a single page tries to charge the
- 		 * page, bail as early as possible.  shmem_unuse() encounters
- 		 * already charged pages, too.  page and memcg binding is
- 		 * protected by the page lock, which serializes swap cache
- 		 * removal, which in turn serializes uncharging.
- 		 */
- 		VM_BUG_ON_PAGE(!PageLocked(page), page);
- 		if (page_memcg(compound_head(page)))
- 			goto out;
+ 	return ret;
+ }
  
- 		id = lookup_swap_cgroup_id(ent);
- 		rcu_read_lock();
- 		memcg = mem_cgroup_from_id(id);
- 		if (memcg && !css_tryget_online(&memcg->css))
- 			memcg = NULL;
- 		rcu_read_unlock();
- 	}
+ /**
+  * mem_cgroup_swapin_charge_page - charge a newly allocated page for swapin
+  * @page: page to charge
+  * @mm: mm context of the victim
+  * @gfp: reclaim mode
+  * @entry: swap entry for which the page is allocated
+  *
+  * This function charges a page allocated for swapin. Please call this before
+  * adding the page to the swapcache.
+  *
+  * Returns 0 on success. Otherwise, an error code is returned.
+  */
+ int mem_cgroup_swapin_charge_page(struct page *page, struct mm_struct *mm,
+ 				  gfp_t gfp, swp_entry_t entry)
+ {
+ 	struct mem_cgroup *memcg;
+ 	unsigned short id;
+ 	int ret;
  
- 	if (!memcg) {
- 		if (!mm) {
- 			memcg = get_mem_cgroup_from_current();
- 			if (!memcg)
- 				memcg = get_mem_cgroup_from_mm(current->mm);
- 		} else {
- 			memcg = get_mem_cgroup_from_mm(mm);
- 		}
- 	}
+ 	if (mem_cgroup_disabled())
+ 		return 0;
  
- 	ret = try_charge(memcg, gfp_mask, nr_pages);
- 	if (ret)
- 		goto out_put;
+ 	id = lookup_swap_cgroup_id(entry);
+ 	rcu_read_lock();
+ 	memcg = mem_cgroup_from_id(id);
+ 	if (!memcg || !css_tryget_online(&memcg->css))
+ 		memcg = get_mem_cgroup_from_mm(mm);
+ 	rcu_read_unlock();
  
- 	css_get(&memcg->css);
- 	commit_charge(page, memcg);
+ 	ret = __mem_cgroup_charge(page, memcg, gfp);
  
- 	local_irq_disable();
- 	mem_cgroup_charge_statistics(memcg, page, nr_pages);
- 	memcg_check_events(memcg, page);
- 	local_irq_enable();
+ 	css_put(&memcg->css);
+ 	return ret;
+ }
  
+ /*
+  * mem_cgroup_swapin_uncharge_swap - uncharge swap slot
+  * @entry: swap entry for which the page is charged
+  *
+  * Call this function after successfully adding the charged page to swapcache.
+  *
+  * Note: This function assumes the page for which swap slot is being uncharged
+  * is order 0 page.
+  */
+ void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry)
+ {
  	/*
  	 * Cgroup1's unified memory+swap counter has been charged with the
  	 * new swapcache page, finish the transfer by uncharging the swap

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

             reply	other threads:[~2021-03-18  6:18 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18  6:17 Stephen Rothwell [this message]
2021-03-18 17:54 ` linux-next: manual merge of the akpm-current tree with the block tree Shakeel Butt
2021-03-18 18:19   ` Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2021-06-02  5:40 Stephen Rothwell
2021-04-07  9:18 Stephen Rothwell
2020-11-17  5:05 Stephen Rothwell
2020-10-15  6:27 Stephen Rothwell
2020-09-25  9:57 Stephen Rothwell
2019-05-03  9:10 Stephen Rothwell
2019-05-03 12:35 ` Amir Goldstein
2018-10-02  7:21 Stephen Rothwell
2018-08-13  7:51 Stephen Rothwell
2018-08-02  8:31 Stephen Rothwell
2018-03-19  6:36 Stephen Rothwell
2016-07-13  6:14 Stephen Rothwell
2016-07-13 16:31 ` Jens Axboe
2015-12-07  8:12 Stephen Rothwell
2015-12-07 19:44 ` Andrew Morton
2015-12-07 20:24   ` Stephen Rothwell
2015-11-01 15:51 Stephen Rothwell
2015-11-01 16:04 ` kbuild test robot
2015-11-01 16:05 ` kbuild test robot
2015-11-01 18:38 ` Mel Gorman
2015-11-01 21:51   ` Stephen Rothwell
2015-01-21  7:14 Stephen Rothwell
2014-07-02  6:06 Stephen Rothwell
2013-11-05  6:29 Stephen Rothwell
2013-11-05  6:25 Stephen Rothwell

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=20210318171720.61a3f59c@canb.auug.org.au \
    --to=sfr@canb.auug.org.au \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=schatzberg.dan@gmail.com \
    --cc=shakeelb@google.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;
as well as URLs for NNTP newsgroup(s).