From patchwork Tue Nov 6 09:55:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 10670019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78D8C14BD for ; Tue, 6 Nov 2018 09:55:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66D6422362 for ; Tue, 6 Nov 2018 09:55:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A0BD2882E; Tue, 6 Nov 2018 09:55:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.4 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,SUBJ_OBFU_PUNCT_FEW,SUBJ_OBFU_PUNCT_MANY autolearn=no version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFDAB22362 for ; Tue, 6 Nov 2018 09:55:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9D1A6B02FE; Tue, 6 Nov 2018 04:55:35 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E4CB16B0300; Tue, 6 Nov 2018 04:55:35 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3BE16B0301; Tue, 6 Nov 2018 04:55:35 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 787F36B02FE for ; Tue, 6 Nov 2018 04:55:35 -0500 (EST) Received: by mail-ed1-f70.google.com with SMTP id g16-v6so5412865eds.20 for ; Tue, 06 Nov 2018 01:55:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:mime-version:content-transfer-encoding; bh=x3QB24GscqKW6OlfJNvDgSgXHJOuhucfbfMPrZrMSTQ=; b=oqp8rPiCYvicJBLEzWY+sbA3Q+WQR4MACg60mUEj6CRqmb0yWfFaMTDz73wnkCqbMd Dvp5H5SLq7dtcJAc+yqGONBz7VqzfqI4PXHgz0we9ATo8VMB4IwzCvQJt8onCFyc2DQE wXy8NHI0lf9zpWMhTidJuMq6YJKcc3kFd/HuPDm4rBeG46PPBhlH7pHRLIrSuiurj1Od ckTPZD7+y7OrnBUKb1RD4NiEQAKA/0l6ppUoDZivmOSeTcO60/e/69kEGzRGSTlneScL vXlIQ5l7qppdS/3/WSSjRR3afy0iw4oZykha7p4qu3Rb9CmILoXDYCR8Dzy+X7MJ3Nqg UFVQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Gm-Message-State: AGRZ1gL/5K13fRxi4duqNqu5RToQG0q3i24Wsk8TLhaoq3kA+mnNwXu+ +OsQS2bQBDWSj1zb4EdyRIliN0xMl/MzTr3SXGjtQCHUFgxJhXWkam9DhU6RRaSWq9uVviTgzaB oOBSyRZ42m9ZDL6AlG+4RCplN+eeSBGj2PoycO5MeY13TTSqAj+sFRT6C96hRdkZpfkUMTxMg0n dnMRJx2rqoaKf4AwjT+JB98Acrj07MEK4oQkk/3kn871EpuybXWEAadl1h59B0cMmXcyTFv7RsE H4xuMkNZmKQJ4IubVZut1V0gyevMGUmOzLw3Xse7w8Wqz8nxeXKGuCHgGNXnhi9nPT/O46UxLpY z/6agWPY48wvLAJqqG6bc6FxyisMVYp0TbW9VBZggT0Pn9XAwbR0zaEOZvuaCwf7AxewdUl8Xw= = X-Received: by 2002:a17:906:8314:: with SMTP id j20-v6mr16934760ejx.60.1541498134949; Tue, 06 Nov 2018 01:55:34 -0800 (PST) X-Received: by 2002:a17:906:8314:: with SMTP id j20-v6mr16934730ejx.60.1541498134016; Tue, 06 Nov 2018 01:55:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541498133; cv=none; d=google.com; s=arc-20160816; b=L8mXfHeQWArF8gsH2rjaGlFn3HK8fE/KLYqqTDowtEAqQfIvSwxBjtZx6VPQLZ9Awr GdW80XgPwZOOZmuPVM7Ckn+a8S2U7PTE+iXxGMil1JnWcvUyz6Feehomm26r5qrJYWo3 jqiQYLF6oUKhA+E8NrF7HXmNDeX/ZPMtldlm/P/LM5AlNHdB6XCKMbnxavk9Tjw6m8Ye 8o1lkvd1uFXcdayp8gKuOZU2QuU27jvYTDpHsh1V/kz9j2URg0tWf5B6Qhg5JsC7n1CT EtnlUepxNLgpRWBdMMe7XMPVCOuZE/URr32lRSU/dOkWLlRXD0s1ZtDFdrQX9SvbtkTs cuPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=x3QB24GscqKW6OlfJNvDgSgXHJOuhucfbfMPrZrMSTQ=; b=E0cSzpSv7ytTljdCH10+1eR622r1RGkJ/KQz9P9LRcVC+7JWnOz7dHDJOWc5uOlCbe jobw8FiiQ2mD03YecaFaHeBGupyvGLb8iMwiDIoJoGucK6Xdt4etVnyLPcITRpzpmsUl 9sd4LB4UUc+L7eYcq13WLhqb04g9eFu9GuUYStPMHzq4rw38KkWrxGTIefu3Kr/RQtR4 nearrTDn5FdgsHfIxSEVbQtJcxofK9klogMlffksQ037hQI1248C5b0dB23Z+I0SRiGe BcJibbYc2Se1E2P/JipmjDOZARurXWfFUPI84ccyNgx+lcIsmLq+Ub+SsKKjsv2ilEaZ B88A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id o58-v6sor27771723edc.21.2018.11.06.01.55.33 for (Google Transport Security); Tue, 06 Nov 2018 01:55:33 -0800 (PST) Received-SPF: pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Google-Smtp-Source: AJdET5e6Y/4UEzYitJHRDi9SVaYsmhKzVjuRWC8WSCVZyBRihPZ/cCHv6hil1p3VDbsWL4FOmdp5iQ== X-Received: by 2002:a50:a9c4:: with SMTP id n62-v6mr20483983edc.187.1541498133562; Tue, 06 Nov 2018 01:55:33 -0800 (PST) Received: from tiehlicka.suse.cz (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id gp22-v6sm1431007ejb.4.2018.11.06.01.55.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 01:55:32 -0800 (PST) From: Michal Hocko To: Andrew Morton Cc: Baoquan He , Oscar Salvador , , LKML , Michal Hocko Subject: [PATCH] mm, memory_hotplug: check zone_movable in has_unmovable_pages Date: Tue, 6 Nov 2018 10:55:24 +0100 Message-Id: <20181106095524.14629-1-mhocko@kernel.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Michal Hocko Page state checks are racy. Under a heavy memory workload (e.g. stress -m 200 -t 2h) it is quite easy to hit a race window when the page is allocated but its state is not fully populated yet. A debugging patch to dump the struct page state shows : [ 476.575516] has_unmovable_pages: pfn:0x10dfec00, found:0x1, count:0x0 : [ 476.582103] page:ffffea0437fb0000 count:1 mapcount:1 mapping:ffff880e05239841 index:0x7f26e5000 compound_mapcount: 1 : [ 476.592645] flags: 0x5fffffc0090034(uptodate|lru|active|head|swapbacked) Note that the state has been checked for both PageLRU and PageSwapBacked already. Closing this race completely would require some sort of retry logic. This can be tricky and error prone (think of potential endless or long taking loops). Workaround this problem for movable zones at least. Such a zone should only contain movable pages. 15c30bc09085 ("mm, memory_hotplug: make has_unmovable_pages more robust") has told us that this is not strictly true though. Bootmem pages should be marked reserved though so we can move the original check after the PageReserved check. Pages from other zones are still prone to races but we even do not pretend that memory hotremove works for those so pre-mature failure doesn't hurt that much. Reported-and-tested-by: Baoquan He Acked-by: Baoquan He Fixes: "mm, memory_hotplug: make has_unmovable_pages more robust") Signed-off-by: Michal Hocko Reviewed-by: Oscar Salvador Acked-by: Balbir Singh --- Hi, this has been reported [1] and we have tried multiple things to address the issue. The only reliable way was to reintroduce the movable zone check into has_unmovable_pages. This time it should be safe also for the bug originally fixed by 15c30bc09085. [1] http://lkml.kernel.org/r/20181101091055.GA15166@MiWiFi-R3L-srv mm/page_alloc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 863d46da6586..c6d900ee4982 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7788,6 +7788,14 @@ bool has_unmovable_pages(struct zone *zone, struct page *page, int count, if (PageReserved(page)) goto unmovable; + /* + * If the zone is movable and we have ruled out all reserved + * pages then it should be reasonably safe to assume the rest + * is movable. + */ + if (zone_idx(zone) == ZONE_MOVABLE) + continue; + /* * Hugepages are not in LRU lists, but they're movable. * We need not scan over tail pages bacause we don't