Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp348288rdb; Fri, 6 Oct 2023 05:34:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEiSLHg+jZ+GnKb+xG98Wfia3/a8Y93/iiiKCDmU9No7+bx1+AThpwpkzxUb19gb1NcNr21 X-Received: by 2002:a05:6a00:a26:b0:68f:c215:a825 with SMTP id p38-20020a056a000a2600b0068fc215a825mr8573337pfh.12.1696595677668; Fri, 06 Oct 2023 05:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696595677; cv=none; d=google.com; s=arc-20160816; b=Yww7cyyRicjcIzAlEv0EhldjEwOVOodgWXCVdxyIGe1LW5UUlcta2HdFpluZah/8Mb FXSik9BHhqzybklaaXaf9X3BVoXS3kqIQoK1L6kyfodXkaCBMQMrgYgTtbd6ehaf0hdn a9lGKw6cH1jGovb06+oH+3UEDd/YpAPeZZ8KRLrECEKFPEqvq/GLs1OgA8oe4zzITBzR GpXYfhNkJ2S4lX36r0f4ozpQmZMpHMXYSlmHwG6TGzL2BaNj/PiZT/KrMAFVv9MiZox6 XrDbGewnQpDtDtYpaWktHZ1oIL0bT/PtutRefAMCNcWm+7cR2sxE1nh0vySRsd+DBnuF w/UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=kp2picVzpjCiZ5thzoNnS4NIffKCsvdoirWsfiXrjmU=; fh=ZpPM5F0wcgWMxdeWIYUMLou/jwX+Zs2Qj02PaNK85hg=; b=QFRYX8obW6vY58HQJmIKGI0Mvfcbz0VVTpDjC40niKoOg5WrvMVZztjeKrwfGtgiZS CMDfDwqtMfFQthsjGdjb1j7cCgcX4SS8uNeR6REywwj8ma5y3GgNFzYEcsBOVDeV3l1y q+6V65L/u45Gh/g9DCA8CzxUAlOWlU7YuJfX5hclZ2ey8GCShMHNeHVPI4NgxKPGB+p6 7UXoTn4CT9n+IJuStv5IK475vsQjGV7OcVuFkP4YyN2QywSP5oFC8hRYKOt8gDw/da51 t3AHSd/pLc4qjrXUCRfL4CyRfGmvyTQDDptzjuKvSsTRhDvmMFRO9Pqf6IRow6wxwfr9 sqjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Dsy1O4s4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id u190-20020a6385c7000000b00578d0d070f4si3618423pgd.844.2023.10.06.05.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 05:34:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Dsy1O4s4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id BAC3D801BC80; Fri, 6 Oct 2023 05:34:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232159AbjJFMeZ (ORCPT + 99 others); Fri, 6 Oct 2023 08:34:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232146AbjJFMeX (ORCPT ); Fri, 6 Oct 2023 08:34:23 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42521CE for ; Fri, 6 Oct 2023 05:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696595616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kp2picVzpjCiZ5thzoNnS4NIffKCsvdoirWsfiXrjmU=; b=Dsy1O4s4pjitIvwNMlEbQcVUUJngbjIVMAT4kpJD/P0KhmAy1ElxGpekoc4rAVAhLgVeGa 62gJO22noiYvqAfNgZWO0HUem1Su+SHhxlUo4etIGgeM5ZwxaemxM31dK1Yw+XvhGwuU/I X/qzCwz/jPL0W2KrTekBCGeRq+QyRq0= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-167-p4-yOYXoNoupVgZLPvhCmw-1; Fri, 06 Oct 2023 08:33:30 -0400 X-MC-Unique: p4-yOYXoNoupVgZLPvhCmw-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-406710d9a4aso15180565e9.2 for ; Fri, 06 Oct 2023 05:33:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696595609; x=1697200409; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kp2picVzpjCiZ5thzoNnS4NIffKCsvdoirWsfiXrjmU=; b=wtgYrw4Yp2zb0AMRaFfxeYA3RrWYLmF+NXuyqHlWMOmnQMl7TrNFxL5PSfTXrumS3Q 2w4pzZtvR2iyEdrlSE+m2tZXO4VCe7z9hKcDn5OQyMMbKCWD0AfLu9YjuOircPaypXFH hw2itOiHIXnnclYkoHJpXRhvxVIDv2F6RcQK9cF6PLNfdkR/XgSScgRtGdPLvLwYYZHi 18r4TVWrpRJfwVfLXGZE1PslPItVIfzj1Yz062pZN+LkakqtkZhs/UtJ8YhXiQzrJBDr XdGHwwQDp4glw3z3xcaZGHHE9sfT4ty8zJHybl97MapneSghfQb6BePb17rzr7AHG41r XsbQ== X-Gm-Message-State: AOJu0YxSJjRDm71Xk/F3Po87yb1+AvIHYBWEyJAR9vW4eJTH8q2IwLDv 8msqJJy+vX5jREoG5yZk+Z8uj85mj7hsLMZpXW67H39Fw/eHUe7Xg4flkygfYLxrnln9ELAkOKw VpsnpeSYZ3biF8QSFpQ+jEuNV X-Received: by 2002:a7b:c84d:0:b0:3fa:934c:8356 with SMTP id c13-20020a7bc84d000000b003fa934c8356mr7567189wml.10.1696595609214; Fri, 06 Oct 2023 05:33:29 -0700 (PDT) X-Received: by 2002:a7b:c84d:0:b0:3fa:934c:8356 with SMTP id c13-20020a7bc84d000000b003fa934c8356mr7567153wml.10.1696595608689; Fri, 06 Oct 2023 05:33:28 -0700 (PDT) Received: from ?IPV6:2003:cb:c715:ee00:4e24:cf8e:3de0:8819? (p200300cbc715ee004e24cf8e3de08819.dip0.t-ipconnect.de. [2003:cb:c715:ee00:4e24:cf8e:3de0:8819]) by smtp.gmail.com with ESMTPSA id y4-20020a05600c364400b0040472ad9a3dsm3666144wmq.14.2023.10.06.05.33.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Oct 2023 05:33:28 -0700 (PDT) Message-ID: <1d606139-9fff-a00e-c09b-587a8b6736f2@redhat.com> Date: Fri, 6 Oct 2023 14:33:27 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v4 1/2] mm/memory_hotplug: split memmap_on_memory requests across memblocks Content-Language: en-US To: "Verma, Vishal L" , "Williams, Dan J" , "Jiang, Dave" , "osalvador@suse.de" , "akpm@linux-foundation.org" Cc: "dave.hansen@linux.intel.com" , "Huang, Ying" , "linux-mm@kvack.org" , "aneesh.kumar@linux.ibm.com" , "linux-kernel@vger.kernel.org" , "linux-cxl@vger.kernel.org" , "Hocko, Michal" , "nvdimm@lists.linux.dev" , "jmoyer@redhat.com" , "Jonathan.Cameron@Huawei.com" References: <20230928-vv-kmem_memmap-v4-0-6ff73fec519a@intel.com> <20230928-vv-kmem_memmap-v4-1-6ff73fec519a@intel.com> <7893b6a37a429e2f06f2b65009f044208f904b32.camel@intel.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <7893b6a37a429e2f06f2b65009f044208f904b32.camel@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 06 Oct 2023 05:34:35 -0700 (PDT) On 03.10.23 22:03, Verma, Vishal L wrote: > On Mon, 2023-10-02 at 11:28 +0200, David Hildenbrand wrote: >> >>> + >>> +static int __ref try_remove_memory(u64 start, u64 size) >>> +{ >>> +       int rc, nid = NUMA_NO_NODE; >>> + >>> +       BUG_ON(check_hotplug_memory_range(start, size)); >>> + >>> +       /* >>> +        * All memory blocks must be offlined before removing memory.  Check >>> +        * whether all memory blocks in question are offline and return error >>> +        * if this is not the case. >>> +        * >>> +        * While at it, determine the nid. Note that if we'd have mixed nodes, >>> +        * we'd only try to offline the last determined one -- which is good >>> +        * enough for the cases we care about. >>> +        */ >>> +       rc = walk_memory_blocks(start, size, &nid, check_memblock_offlined_cb); >>> +       if (rc) >>> +               return rc; >>> + >>> +       /* >>> +        * For memmap_on_memory, the altmaps could have been added on >>> +        * a per-memblock basis. Loop through the entire range if so, >>> +        * and remove each memblock and its altmap. >>> +        */ >>> +       if (mhp_memmap_on_memory()) { >>> +               unsigned long memblock_size = memory_block_size_bytes(); >>> +               u64 cur_start; >>> + >>> +               for (cur_start = start; cur_start < start + size; >>> +                    cur_start += memblock_size) >>> +                       __try_remove_memory(nid, cur_start, memblock_size); >>> +       } else { >>> +               __try_remove_memory(nid, start, size); >>> +       } >>> + >>>         return 0; >>>   } >> >> Why is the firmware, memblock and nid handling not kept in this outer >> function? >> >> We really shouldn't be doing per memory block what needs to be done per >> memblock: remove_memory_block_devices() and arch_remove_memory(). > > > Ah yes makes sense since we only do create_memory_block_devices() and > arch_add_memory() in the per memory block inner loop during addition. > > How should the locking work in this case though? Sorry, I had to process a family NMI the last couple of days. > > The original code holds the mem_hotplug_begin() lock over > arch_remove_memory() and all of the nid and memblock stuff. Should I > just hold the lock and release it in the inner loop for each memory > block, and then also acquire and release it separately for the memblock > and nid stuff in the outer function? I think we have to hold it over the whole operation. I saw that you sent a v5, I'll comment there. -- Cheers, David / dhildenb