Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3205053imu; Sat, 24 Nov 2018 00:03:53 -0800 (PST) X-Google-Smtp-Source: AFSGD/XJmtpjXhkOD3vaw9vB8Kufr4p+lgcbWJfA3KHlETHb0y7LscHzx75x/hKE1C7pJ+29JBS3 X-Received: by 2002:a17:902:a710:: with SMTP id w16mr18718664plq.95.1543046633216; Sat, 24 Nov 2018 00:03:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543046633; cv=none; d=google.com; s=arc-20160816; b=ff9BaSY57MlSAZhXNEnF9Tte3IBhnCVb7G1sJg4ilSGxTXxks9wbVJu6AWBln8dGLR h0qlbj0Z4R9Oq/ZVF8DtYKBusa3C7PfR3emea7oryqA1ui72LZhVhl90C6Q9qSbINv+Q V3b2LuGCfBM/6NNl/72RyUek4vEI7o3C/KgDyIMPdySceGMb6kJaL7T5dTYaQpWzziWp LpgXROL3LoNnnUivVoR5sgV1DnLCXW50YhkKSYQc7M2tWWoRBodeJJjIvEO0sHohrRQ1 atkJgHL0/AD5T1w0lYRuEiyqrqGLMfk/72qFoqUnhA9OHR+T7U009cW71hh9+1cM5xPZ gphw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=TXuPs5Z1LpOs0CF2TiDrolQ/+qm3ZKjXXbbFgGUKl5E=; b=mthXPE+FkTb0TVP8+Mk2gP/9ocPnbGE2+2fSGrgkdRTtybEk61YAiEBftpYW2BqmyJ pzNXW8rn2f9lPf6YUMb7/q+oY1jrUNwdRCMdbRkixKqoQW3faGJBV6QUsDOu3nPMUDwO lSNF0h0Z+GVg8mPDJ0D/AplKT9zB8YnN6bdUXzoXlXXy7xqnDEJmf3LrfcCGQA13ZQlc TZTdzyy9H4y0QzJw5w1pMk/MxFrV/JtWqxmB8xJPUBBe7b+anA4oy/Bi5sn2dpCJmK/G ogh+rIHeoxHaTXDTi9L4gR/8vNSbe5xjSWP9ZrpYxxwPQlKXwR5AUeCMpprV/kY3ZwAA LtHA== 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=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l23si54476162pgh.533.2018.11.24.00.03.38; Sat, 24 Nov 2018 00:03:53 -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=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502226AbeKWRqI (ORCPT + 99 others); Fri, 23 Nov 2018 12:46:08 -0500 Received: from relay.sw.ru ([185.231.240.75]:57032 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389987AbeKWRqI (ORCPT ); Fri, 23 Nov 2018 12:46:08 -0500 Received: from [172.16.25.169] by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gQ5UX-0000hx-Qp; Fri, 23 Nov 2018 10:03:05 +0300 Subject: Re: [PATCH 2/2] mm: ksm: do not block on page lock when searching stable tree To: Yang Shi , mhocko@kernel.org, vbabka@suse.cz, hannes@cmpxchg.org, hughd@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1541618201-120667-1-git-send-email-yang.shi@linux.alibaba.com> <1541618201-120667-2-git-send-email-yang.shi@linux.alibaba.com> From: Kirill Tkhai Message-ID: <302f3116-7e53-2750-ec2d-b90feb4cafec@virtuozzo.com> Date: Fri, 23 Nov 2018 10:03:04 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <1541618201-120667-2-git-send-email-yang.shi@linux.alibaba.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07.11.2018 22:16, Yang Shi wrote: > ksmd need search stable tree to look for the suitable KSM page, but the > KSM page might be locked for long time due to i.e. KSM page rmap walk. > > It sounds not worth waiting for the lock, the page can be skip, then try > to merge it in the next scan to avoid long stall if its content is > still intact. > > Introduce async mode to get_ksm_page() to not block on page lock, like > what try_to_merge_one_page() does. > > Return -EBUSY if trylock fails, since NULL means not find suitable KSM > page, which is a valid case. > > Signed-off-by: Yang Shi Reviewed-by: Kirill Tkhai > --- > mm/ksm.c | 29 +++++++++++++++++++++++++---- > 1 file changed, 25 insertions(+), 4 deletions(-) > > diff --git a/mm/ksm.c b/mm/ksm.c > index 5b0894b..576803d 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -667,7 +667,7 @@ static void remove_node_from_stable_tree(struct stable_node *stable_node) > } > > /* > - * get_ksm_page: checks if the page indicated by the stable node > + * __get_ksm_page: checks if the page indicated by the stable node > * is still its ksm page, despite having held no reference to it. > * In which case we can trust the content of the page, and it > * returns the gotten page; but if the page has now been zapped, > @@ -685,7 +685,8 @@ static void remove_node_from_stable_tree(struct stable_node *stable_node) > * a page to put something that might look like our key in page->mapping. > * is on its way to being freed; but it is an anomaly to bear in mind. > */ > -static struct page *get_ksm_page(struct stable_node *stable_node, bool lock_it) > +static struct page *__get_ksm_page(struct stable_node *stable_node, > + bool lock_it, bool async) > { > struct page *page; > void *expected_mapping; > @@ -728,7 +729,14 @@ static struct page *get_ksm_page(struct stable_node *stable_node, bool lock_it) > } > > if (lock_it) { > - lock_page(page); > + if (async) { > + if (!trylock_page(page)) { > + put_page(page); > + return ERR_PTR(-EBUSY); > + } > + } else > + lock_page(page); > + > if (READ_ONCE(page->mapping) != expected_mapping) { > unlock_page(page); > put_page(page); > @@ -751,6 +759,11 @@ static struct page *get_ksm_page(struct stable_node *stable_node, bool lock_it) > return NULL; > } > > +static struct page *get_ksm_page(struct stable_node *stable_node, bool lock_it) > +{ > + return __get_ksm_page(stable_node, lock_it, false); > +} > + > /* > * Removing rmap_item from stable or unstable tree. > * This function will clean the information from the stable/unstable tree. > @@ -1675,7 +1688,11 @@ static struct page *stable_tree_search(struct page *page) > * It would be more elegant to return stable_node > * than kpage, but that involves more changes. > */ > - tree_page = get_ksm_page(stable_node_dup, true); > + tree_page = __get_ksm_page(stable_node_dup, true, true); > + > + if (PTR_ERR(tree_page) == -EBUSY) > + return ERR_PTR(-EBUSY); > + > if (unlikely(!tree_page)) > /* > * The tree may have been rebalanced, > @@ -2062,6 +2079,10 @@ static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item) > > /* 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; >