From patchwork Thu Jul 12 22:45:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 10522391 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A227602C8 for ; Thu, 12 Jul 2018 22:45:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E3D029A3D for ; Thu, 12 Jul 2018 22:45:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F92329A4F; Thu, 12 Jul 2018 22:45:58 +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 CE5AD29A3D for ; Thu, 12 Jul 2018 22:45:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFE776B0006; Thu, 12 Jul 2018 18:45:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DAC9E6B0008; Thu, 12 Jul 2018 18:45:56 -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 C268A6B000A; Thu, 12 Jul 2018 18:45:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id 8118E6B0006 for ; Thu, 12 Jul 2018 18:45:56 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id e1-v6so18038656pld.23 for ; Thu, 12 Jul 2018 15:45:56 -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:date:from:to :cc:subject:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OMXB1B8DIJDPxP59e5clPKcNrTOuflQpHN0QB6sg5qo=; b=GbPErAFi+SUwy49+MUKujuDH5JgOSKQflbOJxDwXUYcTNyuQtUw3NQftQH6XIOlEmu kGD3zrRjUKRrhv3AAHG0vGi4oPHOPiRjd7OeZZV8QpqZjTxaj2UweYBR0f9XoQ6m31Dn 8whKlAoxnhfXVNAL1onI90Xdm4+ZDetYCCubSwztYYy8amPDJyAY9qRyWNwUQRMq1DEC scyDqdmBGouR6FqXFp56XiA+8gP2yhXPWva+s1QB/O/kE6/Nm4ThwpCQ8OvcFMMLwJA0 N0/CjPDA9O+MZtW0+WFYmIFBfspbZJhuvzNOEIN7T4JZIrrLzVLJx7Trts92/PYbArND Cnfw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Gm-Message-State: AOUpUlE9yUpZA0QiACeTIFv/X7nPViEMtCj0bQ5dNo3og3XiTtAqPwIo 8dCwXPdmCb5w8YgV6AEy1virjuyD8pkcrK33psYYIOV/YSMByjAVgefeBXSaPupgG+Q2lCPKxyr MQNbmjbmLjQwj/axfAiAlh5juEarWjLcn4b9n0SVNTDvnGTH7QVvoENFGHc2/aA420g== X-Received: by 2002:a62:998:: with SMTP id 24-v6mr4230074pfj.99.1531435556196; Thu, 12 Jul 2018 15:45:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe686oVvHX+dIcT6ZoR2fB/J/BghJyVw9D/Vh3eyAqziVKix6D6zyiJE1htXzv/BrMWa5OK X-Received: by 2002:a62:998:: with SMTP id 24-v6mr4230034pfj.99.1531435555264; Thu, 12 Jul 2018 15:45:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531435555; cv=none; d=google.com; s=arc-20160816; b=keO6hep9jW6d2kPHMHTxAkfRYq3xKf8hNXJleb4Qim4OZgqBPv4pERTCZpes8yHlOC FMdIBiKGEXyPby/LTFvoe2WVOsDGLUmhGoPCAQ7Ydz1xY1uDDcwDuxaAzlzc1nPPpGSL mQQOUQkaG3yH97gi1UqaguzAMc+tmH7X550kjl4QBkcHplTBwwF0kaO25vqUBKt0TGMu gzLUjA5UrWThay5elHcOJMHS0IHouIb3vY7SPxZKhiYaII94Mu02zsGwzO7/0jEKQ+ZF H6VCx+yuDsZB5H5LB7IQL4qKDKVUsojeRecqDK8Rjwctz6IelUFMKeX9iVtemgi0IfGh DeJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:arc-authentication-results; bh=OMXB1B8DIJDPxP59e5clPKcNrTOuflQpHN0QB6sg5qo=; b=s7Dbk9xW9UWwJiCDTVXkzFJ149o/8f/4UeUZnJDI1yj+nBjHaoNvH8PujWmB1kCmCd Umzg0cD8aMYe6O+dECdJe1g3rzLLS6JqaCKOPbXQ4kBYnNZlBMDCQg/5qlwu3li+UCyN PjC1uFEO5RtWJaVU6tlUJhuLD14ou3TG7cjClDv1Sn7lGhNFy74vzEL7LebQE9nMXndx KNoUVPr9ak+5FOkShT1YYKplBG+ePkCQY2XoMCq5pr9/KFD68wUdqk5mtoblGz9xsIho fwp4LSTeKjCgTjbC5DbwXHXM2wFhwORE2Y/1JU2SP/ttTdvVAPx8zZveabXDg9iBs4iM rhqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org. [140.211.169.12]) by mx.google.com with ESMTPS id x1-v6si16636211pga.480.2018.07.12.15.45.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 15:45:55 -0700 (PDT) Received-SPF: pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.12 as permitted sender) client-ip=140.211.169.12; Authentication-Results: mx.google.com; spf=pass (google.com: domain of akpm@linux-foundation.org designates 140.211.169.12 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org Received: from localhost.localdomain (c-24-4-125-7.hsd1.ca.comcast.net [24.4.125.7]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id DBF33D58; Thu, 12 Jul 2018 22:45:53 +0000 (UTC) Date: Thu, 12 Jul 2018 15:45:52 -0700 From: Andrew Morton To: Pavel Tatashin Cc: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, mhocko@suse.com, linux-mm@kvack.org, dan.j.williams@intel.com, jack@suse.cz, jglisse@redhat.com, jrdr.linux@gmail.com, bhe@redhat.com, gregkh@linuxfoundation.org, vbabka@suse.cz, richard.weiyang@gmail.com, dave.hansen@intel.com, rientjes@google.com, mingo@kernel.org, osalvador@techadventures.net, abdhalee@linux.vnet.ibm.com, mpe@ellerman.id.au Subject: Re: [PATCH v5 1/5] mm/sparse: abstract sparse buffer allocations Message-Id: <20180712154552.db99d1893bcba7f9503534a0@linux-foundation.org> In-Reply-To: <20180712203730.8703-2-pasha.tatashin@oracle.com> References: <20180712203730.8703-1-pasha.tatashin@oracle.com> <20180712203730.8703-2-pasha.tatashin@oracle.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) 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 On Thu, 12 Jul 2018 16:37:26 -0400 Pavel Tatashin wrote: > When struct pages are allocated for sparse-vmemmap VA layout, we first > try to allocate one large buffer, and than if that fails allocate struct > pages for each section as we go. > > The code that allocates buffer is uses global variables and is spread > across several call sites. > > Cleanup the code by introducing three functions to handle the global > buffer: > > sparse_buffer_init() initialize the buffer > sparse_buffer_fini() free the remaining part of the buffer > sparse_buffer_alloc() alloc from the buffer, and if buffer is empty > return NULL > > Define these functions in sparse.c instead of sparse-vmemmap.c because > later we will use them for non-vmemmap sparse allocations as well. > > ... > > +void * __meminit sparse_buffer_alloc(unsigned long size) > +{ > + void *ptr = NULL; > + > + if (sparsemap_buf) { > + ptr = (void *)ALIGN((unsigned long)sparsemap_buf, size); > + if (ptr + size > sparsemap_buf_end) > + ptr = NULL; > + else > + sparsemap_buf = ptr + size; > + } > + return ptr; > +} tweak... diff -puN mm/sparse.c~mm-sparse-abstract-sparse-buffer-allocations-fix mm/sparse.c --- a/mm/sparse.c~mm-sparse-abstract-sparse-buffer-allocations-fix +++ a/mm/sparse.c @@ -491,7 +491,7 @@ void * __meminit sparse_buffer_alloc(uns void *ptr = NULL; if (sparsemap_buf) { - ptr = (void *)ALIGN((unsigned long)sparsemap_buf, size); + ptr = PTR_ALIGN(sparsemap_buf, size); if (ptr + size > sparsemap_buf_end) ptr = NULL; else