Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2597656imd; Fri, 2 Nov 2018 14:17:35 -0700 (PDT) X-Google-Smtp-Source: AJdET5fKc8Su6PsEjtmrJ18JqBOrKFPVCVsdGkyE/vgUF3/amPhNUjvJpPcTKI1uJbhLZ3E1WNPU X-Received: by 2002:a17:902:8d83:: with SMTP id v3-v6mr13209258plo.162.1541193455815; Fri, 02 Nov 2018 14:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541193455; cv=none; d=google.com; s=arc-20160816; b=J3tZOSoCxQKJYOccfs5K1Kjs9nQpblYZadof25zEHTqTfK06E5U1/nL3UOM39b0i7b QCx82cQCqonuiukVkK/C/sCwXfCAN079KEYi8VPX8ZQFBF+BOLKrDHEgz1IddrsSrvag jOznB6qQ+CXkrF6htWwBvgOCIYPOJcvrYQcbUGn6XDN/Rch1ZXb2Cpk/io8Cx0Rn3pYf baAaXHjA3h7irhRMMLRBa3Zt5fXAuT7qR1lya7e3BN3Yk+9LTMfpCpwC25HUZeIJctrK gqCJKfP8YfoqLuZYluPWwu8qnwr4yAfmrMrSWsZbsz+2Vb6ukn0DwEwpJk/5T9ui9wmf 8dEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5mno8dAIKnaDMIRmkPO62K+I1gtEuyi3eGPcIn207xQ=; b=CD7VLdT8TOLGL7KLc5gyMxsgjPqrwfT4vBqpm992VWKE6to1ft5MDO/PcIPScfjt0s L4DVtOwSbKeVDyB0z0f4EiLiA7ucrsw6a/UhZkZJ0agE05HV9J1XELXbHP0XenIrqKMG MeC++p+e0yfVmwgyolICfRrhadZsAxrNg+Xa+HH/UrcP0vu1rKOxxN8UuoB4DlEUO3+1 G4sy7KnswDrH5/sdMxUvhEdBnC1uUCRoFNTHrb8xV4BuK9cqOszpD0T/nn42Uq8rJfZN xOnKYGk7ow0ywCgeWCPEW8Qz+sFRLoT7KBvHEd8IGOJ7mSLaYUuQJGrVQCpgdr0cIF20 fcGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ncGA3AbY; 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 m6-v6si25454596pgh.230.2018.11.02.14.17.20; Fri, 02 Nov 2018 14:17:35 -0700 (PDT) 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=ncGA3AbY; 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 S1727719AbeKCGZb (ORCPT + 99 others); Sat, 3 Nov 2018 02:25:31 -0400 Received: from mail-yw1-f47.google.com ([209.85.161.47]:38481 "EHLO mail-yw1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbeKCGZb (ORCPT ); Sat, 3 Nov 2018 02:25:31 -0400 Received: by mail-yw1-f47.google.com with SMTP id d126-v6so1315558ywa.5 for ; Fri, 02 Nov 2018 14:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5mno8dAIKnaDMIRmkPO62K+I1gtEuyi3eGPcIn207xQ=; b=ncGA3AbYd+cH9/LMyKyKA6/blhZg6dJyCNNww/+5eNPm9Z4jZCabwMjM5cyYJMRev3 BAn4byrhi2+/6NkRDgkLjCRInW6nHcKuwJgHyJclfQ4IKVErKOujXdPmNvItv9I6vTbz KFpHOfmNlQC4k9fF8fxn1PD5uK09hQ2FGqARiMrxUSXZwzjuMZL5k2YnvQ5vPIx09Oep 5YIsJ1ztmSLGFKlaxZ5XISsg3SieoA9tcuE9BAjz9R0VhlQC00izH1ReBbI78kYzZSRu yZs88pnO6ZFskkpWWVsv6BKvYqK5v5IPBrB3H1Y/PfHZ7CzSQ47AlyOltNZrePwvJjI/ lFQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5mno8dAIKnaDMIRmkPO62K+I1gtEuyi3eGPcIn207xQ=; b=iy3vm9YK70PYFhP6Jf6IQjubogPu0eKwKJ1XXQYZdmWp5jwa6MJfq7OrN2zLYyyYg2 9rzXdlW74eWp83UVNStpsMyhG0VwZ+Op6aGm70qxzKZ8nVR8s0Im7gUS6plQx6oc/tGi tfsBBl3OxvSTc05zNoZxsafJhsWKJhFb2dD1XKNyt+yxrmNVqJ2nm3MfKZoCY1yndPPZ U0LUMT0MOqPpXVNgiBrvcDQs8Gn8jGJtv19cUvlJY+DXEzfOfF8enlX1nCxRRZyIzya2 TQnhWAw+pqIh225t7V48pCQEHTtGThbOVlD0hzQti13px2uR+uz++tGjCKHmO7GZKrBx PxRw== X-Gm-Message-State: AGRZ1gL29JG0K3EqHV6Hhb9kZxo1xlCCYP6g8zjVWSMhJYGOdtW/yNRT 8iogNglXWvcMVr3QY3YcZfPe/+CYCN5OeO2DnP8pBw== X-Received: by 2002:a0d:fec6:: with SMTP id o189-v6mr13414300ywf.237.1541193406862; Fri, 02 Nov 2018 14:16:46 -0700 (PDT) MIME-Version: 1.0 References: <4DECD467-AD45-419D-8F0F-1456863274FD@raithlin.com> In-Reply-To: From: Daniel Mentz Date: Fri, 2 Nov 2018 14:16:35 -0700 Message-ID: Subject: Re: lib/genalloc To: alexey.skidanov@intel.com Cc: Stephen Bates , Mathieu Desnoyers , lkml , labbott@redhat.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 2, 2018 at 1:55 PM Alexey Skidanov wrote: > > > > On 11/2/18 9:17 PM, Daniel Mentz wrote: > > On Thu, Nov 1, 2018 at 10:07 AM Alexey Skidanov > > wrote: > >> On 11/1/18 18:48, Stephen Bates wrote: > >>>> I use gen_pool_first_fit_align() as pool allocation algorithm allocating > >>>> buffers with requested alignment. But if a chunk base address is not > >>>> aligned to the requested alignment(from some reason), the returned > >>>> address is not aligned too. > >>> > >>> Alexey > >>> > >>> Can you try using gen_pool_first_fit_order_align()? Will that give you the alignment you need? > >>> > >>> Stephen > >>> > >>> > >> I think it will not help me. Let's assume that the chunk base address is > >> 0x2F400000 and I want to allocate 16MB aligned buffer. I get back the > >> 0x2F400000. I think it happens because of this string in the > >> gen_pool_alloc_algo(): > >> > >> addr = chunk->start_addr + ((unsigned long)start_bit << order); > >> > >> and the gen_pool_first_fit_align() implementation that doesn't take into > >> account the "incorrect" chunk base alignment. > > > > gen_pool_first_fit_align() has no information about the chunk base > > alignment. Hence, it can't take it into account. > > > > How do you request the alignment in your code? > > > > I agree with your analysis that gen_pool_first_fit_align() performs > > alignment only with respect to the start of the chunk not the memory > > address that gen_pool_alloc_algo() returns. I guess a solution would > > be to only add chunks that satisfy all your alignment requirements. In > > your case, you must only add chunks that are 16MB aligned. > > I am unsure whether this is by design, but I believe it's the way that > > the code currently works. > > > > Daniel, > > I think the better solution is to use bitmap_find_next_zero_area_off() > that receives the bit offset (CMA allocator uses it to solve the same > issue). Of course, we need to pass the chunk base address to the > gen_pool_first_fit_align(). > > What do you think? Yeah, I guess you could extend genpool_algo_t to include the information you need i.e. the offset and then provide a modified version of gen_pool_first_fit_align() that does take your offset into account. I wouldn't change gen_pool_first_fit_align(), though, because existing users might depend on the current behavior.