Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2489366imd; Fri, 2 Nov 2018 12:18:06 -0700 (PDT) X-Google-Smtp-Source: AJdET5cw1FJsYE8voksWSI9U/dcVrqHU+6DtM6E7KUZKogm2yjgMvGhynC48YTKD5hAx4MEBdMC5 X-Received: by 2002:a17:902:a5c6:: with SMTP id t6-v6mr12971674plq.31.1541186286371; Fri, 02 Nov 2018 12:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541186286; cv=none; d=google.com; s=arc-20160816; b=yzGIlDB8ZB2ZZh645/+gVC0rB19iezDwy16iWNcMFv3/9OB2lZRCP3c52kUb5qVa/X qog7fI84Q24j+jr4SnU8uI7VHSMdBEyufVfCaAUe9P/tK6AOo8WYqhVF7hy4FuL0s6Ff s3YEpVxnVOoQ0dvntek16Pb5Rsaqhargx4HYm/eaTM/Hu2F9HwOeCvg1hX57EXcG9l8U xcXvmhrjdC3Yy/AbduIlOfTmPhx2OUKZFJaqprUxQwd+drbyAevtg7Soa+yOZheZ8g1O zteLQKftHzJpe/dfnScAA6KFjFU8scn3Khw4zQsaksDmupws1c6abF8asKznWhRAoH3b wDOw== 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=U9n17ZvrmN4pooycrDUxOIX57fKmRrx3N2ZvgVpXxQM=; b=sGtNkGIykez3fn/0BsnrnV+M9dnDFZRmStr7AauzopXhr2a8RE9ysJGVdIvLCEx4VA xBoSm0Zx5LHeiuay7bBXt3Z940fqtsYREh9IMeMq8CLpD2eIxK9QisWWXPyP8znPk5vC x0FMnPOS6I5QusZL5hdfeGS2at5Ra0DPh3C+4glaSeYAb83kJLKTml7pJ6Rr6AnolG+V o2Bs6biTSOZlPQaJD1Lh1TOo/FyYsyC9AbFBEryaYwlcplFKFyDbXNQFcvO/t4FnqZjn +/+BLGcvVQF1KdmZRcYsy0Z9kAURPxCmLOHc3qb11RnSDsjKa7P5ClIAe+c3rdS9lHDI GnIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZROd2EAt; 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 m7-v6si33762268pls.358.2018.11.02.12.17.51; Fri, 02 Nov 2018 12:18:06 -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=ZROd2EAt; 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 S1726147AbeKCEZq (ORCPT + 99 others); Sat, 3 Nov 2018 00:25:46 -0400 Received: from mail-yw1-f49.google.com ([209.85.161.49]:35887 "EHLO mail-yw1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbeKCEZp (ORCPT ); Sat, 3 Nov 2018 00:25:45 -0400 Received: by mail-yw1-f49.google.com with SMTP id h21-v6so1194214ywa.3 for ; Fri, 02 Nov 2018 12:17:23 -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=U9n17ZvrmN4pooycrDUxOIX57fKmRrx3N2ZvgVpXxQM=; b=ZROd2EAtd44gRaTbiTSEpi7xns6bDnaG/2h1NCWu3hcBteaqZVhIirwl5PC0C9oab5 jJ4NrblJlCFBrhLoLweloObOMe9+bMM1XGd5TlcF6X166ZMiAXKwHN5qSw4vdkXmzGNV QD6abFKtGbEq+OgoLJXCxP8LjyaucUlWqYW8YVVbXY8z+dhKZC0I/bNaTe3EBSkcGJ81 m930fZYGL8IrecCjWzEikfAaeGPUfecDkJax+fHw0hRO1rh6frXuvSwuSMvfdOa0z2es Eucm1tgVqRJsa3lpO04VonEMkgZS1mCzUBllmDUHykvKB8oYOy3yPYH9emjrWJ9ZPivA hPYA== 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=U9n17ZvrmN4pooycrDUxOIX57fKmRrx3N2ZvgVpXxQM=; b=XrG6y9/a2r4RaLt7FyLutbr/uv8STUy/9OPM0K1MxMPXgEjGWBIHGX41N5BzEF40Fh iqTMNgwxraBpI6oEt/3PKjc1jWTTgPpNjjUPusIayAq+fQGLvvdVOf1gvTENZ150h90e gKrxzcYVkwWFiBNhrSW4a9c6QLPhSWNQH1nLRulAnsxjrViKnmHs01xsOzg9PKBsHFZI cZsmepQjqbj2RA2iuFULSkJcMCM7oh/C8ZjV4pRsjkYjKb2di/EAyNcE9F5LRVoDWXMI hborC9bYJQAAwXQsIev0XWRUN7P4ek4Gs19wSv3NI45Bc14cIUxLGpn0oTgP2JVl2Vmp yT+w== X-Gm-Message-State: AGRZ1gK2DxVqrTZYJiuh2ml05wGB06Kx/V3uEoO/7pTrpf73alW2DM8l 80XWCKjRioPxSdLGI0H6FUMhVg1JhGTBVH0M2S42Ag== X-Received: by 2002:a0d:ff46:: with SMTP id p67-v6mr12992400ywf.338.1541186242504; Fri, 02 Nov 2018 12:17:22 -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 12:17:11 -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 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.