Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3835744imj; Tue, 19 Feb 2019 10:13:49 -0800 (PST) X-Google-Smtp-Source: AHgI3IYk+/ebWzOpAVtE21TpA85AP9pRk+eXNY9TNCiSB5HldoLdydPZ+K+RiPRrrwyN3LJXelbq X-Received: by 2002:a17:902:848f:: with SMTP id c15mr31416010plo.119.1550600029904; Tue, 19 Feb 2019 10:13:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550600029; cv=none; d=google.com; s=arc-20160816; b=iIytoPVF3tfsTKDoBunFdNmDwShYrxD4WlchlxnddcwNyR/HISWwiyKNbu432RMdlJ +zMguOOucCoMrATDwduYnBTJoFTktmV/WShXYYYIBQG7Q1NR/StgBuFQfJwf88VCI/ve tFaq7eZbA4Z/yvKlHr12KOUIZ+tD2QSmVGdLhjy7W5tavZClD04Kr1SuVFgqKvQvwpUM m//6X49Peui/M2aRsNe1+JK5FtvoBYA/3doyn0ZCt0iQxkar35FamCcVWSXqZ3W0Pjbm aO+L+FxhLj8dPkRGzUA7eOJHTAfYkFhcZE/21cf0rJCtIQNNYKNKQDIxi7DNUCy81R3l 1rxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=8trljMhUxj9RQgjcslAL5Kc3oZbD3saMNMec1brseHY=; b=L1Q+W/33O8S9mZBx73joxmnjPqEy4yRdF7gjUB6EQo8uh00b1Dhmc3EnAhJGh3fBXH DhQuQCfBWoSx5kmCKEBUHlUf2SD/sSuyLGX//D8U3js0HVfvmoS+B7mKXuTRnA+kUmcd MHKcXNB2wK3nBbFAq6kvBobKC/7do6WHQNOdZmpiaeCQS4J3yZc2Xk03AgsqJM6olxwA YUvfqQ77rGZn1ZVxXYLdzUJGujuu/Pk9PZ3sq1bQjh08qoJbaXcVYyRUzdduxOiWzCNM F/p/C1lcCFoUDQtBcUzKzQN1f20YJlTFA/zctZlHWP06qo/MrQzdegVVjsyy3mAydxbC 9qYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y14si15140937plr.78.2019.02.19.10.13.32; Tue, 19 Feb 2019 10:13:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726610AbfBSSLm (ORCPT + 99 others); Tue, 19 Feb 2019 13:11:42 -0500 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:57812 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725936AbfBSSLl (ORCPT ); Tue, 19 Feb 2019 13:11:41 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R731e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0TKb7nk._1550599893; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TKb7nk._1550599893) by smtp.aliyun-inc.com(127.0.0.1); Wed, 20 Feb 2019 02:11:35 +0800 Subject: Re: [PATCH mmotm] mm: ksm: do not block on page lock when searching stable tree fix To: Hugh Dickins , Andrew Morton Cc: ktkhai@virtuozzo.com, jhubbard@nvidia.com, aarcange@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: From: Yang Shi Message-ID: Date: Tue, 19 Feb 2019 10:11:30 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/18/19 9:26 PM, Hugh Dickins wrote: > I hit the kernel BUG at mm/ksm.c:809! quite easily under KSM swapping > load. That's the BUG_ON(age > 1) in remove_rmap_item_from_tree(). > > There is a comment above it, but explaining in more detail: KSM saves > effort by not fully maintaining the unstable tree like a proper RB > tree throughout, but at the start of each pass forgetting the old tree > and rebuilding anew from scratch. But that means that whenever it looks > like we need to remove an item from the unstable tree, we have to check > whether it has already been linked into the new tree this time around > (hence rb_erase needed), or it's just a free-floating leftover from the > previous tree. > > "age" 0 or 1 says which: but if it's more than 1, then something has > gone wrong: cmp_and_merge_page() was forgetting to remove the item > in the new EBUSY case. > > Signed-off-by: Hugh Dickins > --- > Fix to fold into > mm-ksm-do-not-block-on-page-lock-when-searching-stable-tree.patch Thanks for catching this. The fix looks good to me. > > I like that patch better now it has the mods suggested by John Hubbard; > but what I'd still really prefer to do is to make the patch unnecessary, > by reworking that window of KSM page migration so that there's just no > need for stable_tree_search() to take page lock. We would all prefer > that. However, each time I've gone to do so, it's turned out to need > more care than I expected, and I run out of time. So, let's go with > what we have, and one day I might perhaps get back to it. I agree it needs extra scrutiny to make the code lockless. Regards, Yang > > mm/ksm.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > --- mmotm/mm/ksm.c 2019-02-14 15:16:13.000000000 -0800 > +++ linux/mm/ksm.c 2019-02-18 20:36:44.707310427 -0800 > @@ -2082,10 +2082,6 @@ static void cmp_and_merge_page(struct pa > > /* We first start with searching the page inside the stable tree */ > kpage = stable_tree_search(page); > - > - if (PTR_ERR(kpage) == -EBUSY) > - return; > - > if (kpage == page && rmap_item->head == stable_node) { > put_page(kpage); > return; > @@ -2094,6 +2090,9 @@ static void cmp_and_merge_page(struct pa > remove_rmap_item_from_tree(rmap_item); > > if (kpage) { > + if (PTR_ERR(kpage) == -EBUSY) > + return; > + > err = try_to_merge_with_ksm_page(rmap_item, page, kpage); > if (!err) { > /*