From patchwork Fri Aug 17 15:41:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10569081 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 5656B15E2 for ; Fri, 17 Aug 2018 15:41:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4558C2BD7A for ; Fri, 17 Aug 2018 15:41:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37CDB2BD7D; Fri, 17 Aug 2018 15:41:40 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham 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 B90C12BD7A for ; Fri, 17 Aug 2018 15:41:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89A5C6B08EC; Fri, 17 Aug 2018 11:41:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8490A6B08ED; Fri, 17 Aug 2018 11:41:38 -0400 (EDT) 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 73A146B08EE; Fri, 17 Aug 2018 11:41:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id 148586B08EC for ; Fri, 17 Aug 2018 11:41:38 -0400 (EDT) Received: by mail-wr1-f71.google.com with SMTP id j6-v6so6181311wrr.15 for ; Fri, 17 Aug 2018 08:41:38 -0700 (PDT) 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; bh=rRaWYUc/JL7rh/xe14mXGjzAypZ5GcE+mqKHpK3280M=; b=E3gCVSkegyyfN7T5JAAlpqkFRXw015z0ElT9wkDOtyzJnB7cvxQEsLwMJC7MS7JDFE mhum/jt9t+4tA4UD67i5DtX4EWh+b0ndATCeRZ3ZikqIqo4h6VfDE9Z8tUAdFaubAk7m WmJgMWv/RpAXfSOGyjo/S7U3H8lWO9RcjDfeGGA/KK6XLrQAOrAM4A++kmwu4L5/89P7 fYSXO8tvTeZRC4Yn1/7s7KoJRnwTCCIEhfPzz0RwadrXBIE2v5i/l1rlVXbDp/YJ6xdG UzeXgAtr/SQEOxav4+sF5GZHPouWvHPjh7eWNpViXId+kItGMuGxIoPZ/FTMp+qUllr6 9xMQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Gm-Message-State: AOUpUlGNyZf565rDo+t0sIEcsdSKUz3U/fBfPhhoGdPE3BxPuAP1m0Qr NuEaa+oy7KP3YJizF2+7EoDiE033sXQwkpBeobNOhxj/DijCZD7v5nAAEN4YzVaBQmLlChb6yZb g8CTHGpUD5bwDrw+AR3AzCSxk5vnW6fOgSiQjY4IDOKMdG+7RYQRnn6zofjIjIgFN8Sy1lpVKTm sLKQArBFnUOexQPisAslhLJ9DhjrJKKnxTEDqqUBtdXStQO9GunIOVLEqCE0+i021jDCKhtW7mt 9MYDMTu284kqGJVT6lxxoO5oCxtOZ91dJvts+9l9Qs9qeVGX88npV9AcWIDko3XRf4TVRpzOd7H 3isHrfhWFM9uZCuWwlqWSm6d/pzyzxsjeSgtM7SvJ11zS2tyLrWjm8OypJXRFt8rmQwMwNTXbw= = X-Received: by 2002:a5d:5691:: with SMTP id f17-v6mr23286008wrv.58.1534520497430; Fri, 17 Aug 2018 08:41:37 -0700 (PDT) X-Received: by 2002:a5d:5691:: with SMTP id f17-v6mr23285973wrv.58.1534520496238; Fri, 17 Aug 2018 08:41:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534520496; cv=none; d=google.com; s=arc-20160816; b=zmE+rAQ4OFwDL2leD54p+hJuxyKJNmDIZxjsEkpwqdJAnGCTC16iJlQe/9s/qyfxWA +KHCOt7DgmoBLRqTQdeop/75QA36DfM+sBSUrWjR2OEdM/pE82CVi8am7d5jRLdliTSH 9qXafX5bfv6bgsGvydmzMO60fF2XslhkFT65b8VesMhVcYyBq0+EPZrPnTE3K7W67RFM ycWRKdD6loEEjVWymfG+0z1LsFVbh/k4QRecx9xvUcwsFjBtFlTV6+u+AVhlLTkMCI28 Ni3an3QOc2yIW+575lN/US3Kwh82gjsrEZmQ79NG0FL9I3Gpb0pAZ5JnhERWPdJCIkJZ 6N1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=rRaWYUc/JL7rh/xe14mXGjzAypZ5GcE+mqKHpK3280M=; b=ro7yYZ4Stjd7S4tF045+iY2Efa7uWm15gBYQ8oVglgHTt3gBgDuJbQqInb1jEXm3th iwuARdRkk1moZ0JjkQLaIj5q7LsmchEyZ8rDscJ3fuYMPw0ySOJl7JctqMXRlyhNFAvu n9oH27MPUq4sTqdjpyf2XGd1tgUo7m6/N/3lPxJRw0hlW7rUNmliDl4DvmwMywM9FzBO k9phnQAga8lYc1pUV6uqui/qyetGjv03ybwO5x45B4Y20PX0R6x69ScHbecf13vKw0cq Yged5NvoXB2VIwWWQW3FtizK/rto8t348GV4E4MUeIzIT9AV9UPoIOXt2lIFB/k0S9xk 7SBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m16-v6sor1005572wmb.1.2018.08.17.08.41.35 for (Google Transport Security); Fri, 17 Aug 2018 08:41:36 -0700 (PDT) Received-SPF: pass (google.com: domain of osalvador.vilardaga@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 osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Google-Smtp-Source: AA+uWPxN0CBCYcg5r7zXdpVAJ/biB3a2iZ7W1CHpldg3w5oe9w0IYJ1cm/us37aF1m5/vcsSze5wiA== X-Received: by 2002:a1c:99c2:: with SMTP id b185-v6mr17774997wme.15.1534520495769; Fri, 17 Aug 2018 08:41:35 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id u9-v6sm2218107wrc.43.2018.08.17.08.41.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Aug 2018 08:41:34 -0700 (PDT) Received: from d104.suse.de (nat.nue.novell.com [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id DACFB12492D; Fri, 17 Aug 2018 17:41:33 +0200 (CEST) From: Oscar Salvador To: akpm@linux-foundation.org Cc: mhocko@suse.com, dan.j.williams@intel.com, jglisse@redhat.com, david@redhat.com, jonathan.cameron@huawei.com, Pavel.Tatashin@microsoft.com, yasu.isimatu@gmail.com, logang@deltatee.com, dave.jiang@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [RFC v2 0/2] Do not touch pages in remove_memory path Date: Fri, 17 Aug 2018 17:41:25 +0200 Message-Id: <20180817154127.28602-1-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 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: Oscar Salvador This patchset moves all zone/page handling from the remove_memory path back to the offline_pages stage. This has be done for two reasons: 1) We can access steal pages if we remove memory that was never online [1] 2) Code consistency Currently, when we online memory, online_pages() takes care to initialize the pages and put the memory range into its corresponding zone. So, zone/pgdat's spanned/present pages get resized. But the opposite does not happen when we offline memory. Only present pages is decremented, and we wait to shrink zone/node's spanned_pages until we remove that memory. But as explained above, this is wrong. So this patchset tries to cover this by moving this handling to the place it should be. The main difficulty I faced here was in regard of HMM/devm, as it really handles the hot-add/remove memory particulary, and what is more important, also the resources. I really scratched my head for ideas about how to handle this case, and after some fails I came up with the idea that we could check for the res->flags. Memory resources that goes through the "official" memory-hotplug channels have the IORESOURCE_SYSTEM_RAM flag. This flag is made of (IORESOURCE_MEM|IORESOURCE_SYSRAM). HMM/devm, on the other hand, request and release the resources through devm_request_mem_region/devm_release_mem_region, and these resources do not contain the IORESOURCE_SYSRAM flag. So what I ended up doing is to check for IORESOURCE_SYSRAM in release_mem_region_adjustable. If we see that a resource does not have such a flag, we know that we are dealing with a resource coming from HMM/devm, and so, we do not need to do anything as HMM/dev will take care of that part. I online compiled the code, but I did not test it (I will do next week), but I sent this RFCv2 mainly because I would like to get feedback, and see if the direction I took is the right one. This time I left out [2] because I am working on this in a separate patch, and does not really belong to this patchset. [1] https://patchwork.kernel.org/patch/10547445/ (Reported by David) [2] https://patchwork.kernel.org/patch/10558723/ Oscar Salvador (2): mm/memory_hotplug: Add nid parameter to arch_remove_memory mm/memory_hotplug: Shrink spanned pages when offlining memory arch/ia64/mm/init.c | 6 +- arch/powerpc/mm/mem.c | 12 +--- arch/s390/mm/init.c | 2 +- arch/sh/mm/init.c | 6 +- arch/x86/mm/init_32.c | 6 +- arch/x86/mm/init_64.c | 10 +-- include/linux/memory_hotplug.h | 11 +++- kernel/memremap.c | 16 ++--- kernel/resource.c | 16 +++++ mm/hmm.c | 34 +++++----- mm/memory_hotplug.c | 145 ++++++++++++++++++++++++++--------------- mm/sparse.c | 4 +- 12 files changed, 157 insertions(+), 111 deletions(-)