Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp408097imu; Fri, 21 Dec 2018 00:59:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/XV8Q9atW05v1jdzPZUHCkLi/io8dPwOKV+UiYRmIoz7ih9zqnH0xq8ZMccraJRJLDSNOlu X-Received: by 2002:a62:6ec8:: with SMTP id j191mr1647532pfc.198.1545382744023; Fri, 21 Dec 2018 00:59:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545382743; cv=none; d=google.com; s=arc-20160816; b=eMX1m+47h/y6/tJP+JfQAn6OwJGwatRJmk7nqldzO2HZiyHmkD3eNPlgFNzzfHoNx4 77cQjGH9f4VKFvn53SzlSGo5m6RIPAWfjtfZ+LhzvTNoPD6bOaTZnsxJjwkhE8BYEpVU ch3HgWKmmDFyK7kCY4nZS+uMFxIHH1/1nwHTtEsPHu5/ouh6hLw+pgVwHJSd06Btr3WA srdeiUOMEJpCoCSba6uariz1jFTqaUDJLPzxdVlfnkquoCT1Uvst7jl1jaxfxAUshZf5 3Glk8beZQ9GNCwWa0mukbAowIBXA+bQmf1l0ydkiyFniF7zZpaq6NzGl4PorDqPlEV+X H9ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=SKCcAeW5H4+bwp7AQJhecAcvEZDXW19JmTrsciJug4w=; b=Y43SX1QN6ZEr2gDyeRbDwGB3vuR8sk3jqIGFJJvb/K8njWr5lagMSDX5QQj4tFVqoR +uDtdJnKy9OUPLQEIBvnuEl4wuRpFTc2Sk5qvNcwjCVV60YDMnAXYC9FSf96x1Ox8TcF fS2Wck2w1NNQADc7FZqv5pfc71vP/hzkSC4K74/FXXAEkfFMafQDP297aJ6+jx0BUeq4 1UIkHYilT2Lx8uT4xITPUS9O9WTDUBiYrtOKlt7LpvDzD73vjzfheW6DRoUO5cIF5WR/ VxW3EGy9OGlyNvD3Jrn0z9P32Oaf8flh6/QHUs57ad/tZ2+xeZ69G+aOlPuI+ZusBaj5 Fc5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="d/S+qQm4"; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s8si19806511plq.345.2018.12.21.00.58.48; Fri, 21 Dec 2018 00:59:03 -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; dkim=pass header.i=@google.com header.s=20161025 header.b="d/S+qQm4"; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726383AbeLUGFE (ORCPT + 99 others); Fri, 21 Dec 2018 01:05:04 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:34324 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726023AbeLUGFE (ORCPT ); Fri, 21 Dec 2018 01:05:04 -0500 Received: by mail-oi1-f196.google.com with SMTP id r62so3931580oie.1 for ; Thu, 20 Dec 2018 22:05:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=SKCcAeW5H4+bwp7AQJhecAcvEZDXW19JmTrsciJug4w=; b=d/S+qQm4oJbHT5p9lTGC2fWkz8K5Bk9hacHLmCj3635B3waQQqrx5BsYm1eXsQ0ofN k7bHpO7LzV+uO2KMi4hYje8NjWgipT41BtnXfFpl7apqtWkonhyvTS418Ot0F+mo7a3y 84Jnd3CTPdbUOKlyHDZ3bUenjdcTDasJv6gL6xzs4V8LYgdoEnQ9BTxAWFN+0mB2VCKZ QtlWaUUDtzHcNfPv99vv2HBzd4hsLqY3fMdfvpu22rgvr8iyW+19ZqoNxEvAxn6uzPBw QODcLkazq5Inuis7qhWPuMSl8PeqFYZqoe58/JfDg3UdPdHtyPKY2GFiY4vKkUlKIkia egKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=SKCcAeW5H4+bwp7AQJhecAcvEZDXW19JmTrsciJug4w=; b=EiEGSe264M4qiUKKX5vxzXzLnUkCeeLu2HUhBQk8wq0ctgnbIQxdVbLStiXHl+/5a/ Vl9PAvTLxYZkSsuLTpix7Nrf+l1ozcqecgF00tLg9i8Mlr5jPg746Y+bJz7LqXiAWZwZ TvOxoo5GuxA8wn7UlrYtX57JpwKQBIJrTNBvkPIGQuBcrq/eUnekbF7sYueQikww+mJZ /Bi4eYs5Gf4QVYnin5yq0llzKq0ucNUiZba/R8wLpdgBwxxoU7m0joKLPYL+lNx3+Jg0 TN8XYtgj6s7LOYnocnBxDHuGxnIyokpX5GKrHsF+HqF5hu6YchZ/V+IdgGsF1o8WVbdr dBXg== X-Gm-Message-State: AJcUukcFmF95bUT3al9TPAjE33ASMSA5yMdA7zb8iKb83HIBEcLRNcOg 2EkMGHTe90ZjqzKJZhRD7W6Uow== X-Received: by 2002:a05:6808:155:: with SMTP id h21mr594679oie.34.1545372301828; Thu, 20 Dec 2018 22:05:01 -0800 (PST) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id s186sm11712006oie.13.2018.12.20.22.04.58 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Dec 2018 22:05:00 -0800 (PST) Date: Thu, 20 Dec 2018 22:04:51 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: Yang Shi , mhocko@kernel.org, vbabka@suse.cz, hannes@cmpxchg.org, hughd@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kirill Tkhai , Andrea Arcangeli Subject: Re: [PATCH 1/2] mm: vmscan: skip KSM page in direct reclaim if priority is low In-Reply-To: <20181220144513.bf099a67c1140865f496011f@linux-foundation.org> Message-ID: References: <1541618201-120667-1-git-send-email-yang.shi@linux.alibaba.com> <20181220144513.bf099a67c1140865f496011f@linux-foundation.org> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 20 Dec 2018, Andrew Morton wrote: > > Is anyone interested in reviewing this? Seems somewhat serious. > Thanks. Somewhat serious, but no need to rush. > > From: Yang Shi > Subject: mm: vmscan: skip KSM page in direct reclaim if priority is low > > When running a stress test, we occasionally run into the below hang issue: Artificial load presumably. > > INFO: task ksmd:205 blocked for more than 360 seconds. > Tainted: G E 4.9.128-001.ali3000_nightly_20180925_264.alios7.x86_64 #1 4.9-stable does not contain Andrea's 4.13 commit 2c653d0ee2ae ("ksm: introduce ksm_max_page_sharing per page deduplication limit"). The patch below is more economical than Andrea's, but I don't think a second workaround should be added, unless Andrea's is shown to be insufficient, even with its ksm_max_page_sharing tuned down to suit. Yang, please try to reproduce on upstream, or backport Andrea's to 4.9-stable - thanks. Hugh > "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. > ksmd D 0 205 2 0x00000000 > ffff882fa00418c0 0000000000000000 ffff882fa4b10000 ffff882fbf059d00 > ffff882fa5bc1800 ffffc900190c7c28 ffffffff81725e58 ffffffff810777c0 > 00ffc900190c7c88 ffff882fbf059d00 ffffffff8138cc09 ffff882fa4b10000 > Call Trace: > [] ? __schedule+0x258/0x720 > [] ? do_flush_tlb_all+0x30/0x30 > [] ? free_cpumask_var+0x9/0x10 > [] schedule+0x36/0x80 > [] schedule_timeout+0x206/0x4b0 > [] ? native_flush_tlb_others+0x11f/0x180 > [] ? ktime_get+0x40/0xb0 > [] io_schedule_timeout+0xda/0x170 > [] ? bit_wait+0x60/0x60 > [] bit_wait_io+0x1b/0x60 > [] __wait_on_bit_lock+0x59/0xc0 > [] __lock_page+0x86/0xa0 > [] ? wake_atomic_t_function+0x60/0x60 > [] ksm_scan_thread+0xeb9/0x1430 > [] ? prepare_to_wait_event+0x100/0x100 > [] ? try_to_merge_with_ksm_page+0x850/0x850 > [] kthread+0xe6/0x100 > [] ? kthread_park+0x60/0x60 > [] ret_from_fork+0x46/0x60 > > ksmd found a suitable KSM page on the stable tree and is trying to lock > it. But it is locked by the direct reclaim path which is walking the > page's rmap to get the number of referenced PTEs. > > The KSM page rmap walk needs to iterate all rmap_items of the page and all > rmap anon_vmas of each rmap_item. So it may take (# rmap_item * # > children processes) loops. This number of loops might be very large in > the worst case, and may take a long time. > > Typically, direct reclaim will not intend to reclaim too many pages, and > it is latency sensitive. So it is not worth doing the long ksm page rmap > walk to reclaim just one page. > > Skip KSM pages in direct reclaim if the reclaim priority is low, but still > try to reclaim KSM pages with high priority. > > Link: http://lkml.kernel.org/r/1541618201-120667-1-git-send-email-yang.shi@linux.alibaba.com > Signed-off-by: Yang Shi > Cc: Vlastimil Babka > Cc: Johannes Weiner > Cc: Hugh Dickins > Cc: Michal Hocko > Cc: Andrea Arcangeli > Signed-off-by: Andrew Morton > --- > > mm/vmscan.c | 23 +++++++++++++++++++++-- > 1 file changed, 21 insertions(+), 2 deletions(-) > > --- a/mm/vmscan.c~mm-vmscan-skip-ksm-page-in-direct-reclaim-if-priority-is-low > +++ a/mm/vmscan.c > @@ -1260,8 +1260,17 @@ static unsigned long shrink_page_list(st > } > } > > - if (!force_reclaim) > - references = page_check_references(page, sc); > + if (!force_reclaim) { > + /* > + * Don't try to reclaim KSM page in direct reclaim if > + * the priority is not high enough. > + */ > + if (PageKsm(page) && !current_is_kswapd() && > + sc->priority > (DEF_PRIORITY - 2)) > + references = PAGEREF_KEEP; > + else > + references = page_check_references(page, sc); > + } > > switch (references) { > case PAGEREF_ACTIVATE: > @@ -2136,6 +2145,16 @@ static void shrink_active_list(unsigned > } > } > > + /* > + * Skip KSM page in direct reclaim if priority is not > + * high enough. > + */ > + if (PageKsm(page) && !current_is_kswapd() && > + sc->priority > (DEF_PRIORITY - 2)) { > + putback_lru_page(page); > + continue; > + } > + > if (page_referenced(page, 0, sc->target_mem_cgroup, > &vm_flags)) { > nr_rotated += hpage_nr_pages(page); > _