-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discussion: extra copying justification #304
Comments
I'm not involved here or anything, but
caught my attention in email. I would say pointer arithmetic like that is kind of frowned upon in Go. Is it necessary? |
Removed extra copies. It reduces memory consumption, improves performances and simplifies the result. ITS: linuxboot#304 Signed-off-by: Dmitrii Okunev <xaionaro@fb.com>
Removed extra copies. It reduces memory consumption, improves performances and simplifies the result. ITS: linuxboot#304 Signed-off-by: Dmitrii Okunev <xaionaro@fb.com>
@hugelgupf : Yeah, it's a fair question. But I do so very rarely and in my current case I think (but not sure, yet:) it's justified :) Anyway the library should try to create less constraints if possible ("require less, return more"). And anyway I was hoping to convince to remove copyings using other arguments: first of all, by reducing memory consumption multiple times. |
I did the copying in the past because once you start modifying the files underneath a firmwarewarevolume, during the reconstruction I was seeing some corruption because the firmwarevolume buffer is shared with the file buffer. If we really want to avoid this, I would change this so that the parent buffers terminate after their headers, and not contain the child buffers |
I would +1 on not trying to calculate offsets by subtracting pointers. Lets discuss what you're trying to achieve and maybe we can find another way to do it |
safety is the critical element of fiano, not speed. If there's even a question erring on the side of safety is the right move. |
It seems to me a bad solution to just hide changes. If something was changed underneath it should be shown "over-neath" as well. Is that possible to get an unit-test for the situation you faced then? May be I will find a way to fix the problem without copying. I would be happy to try to do so :)
It's a too long and unrelated discussion, IMHO, because it would require to explain details of the program I work on (and discuss some other decisions). And anyway I doubt it's possible to find another elegant way to do what I need. So as I said:
So I suggest to just forget about pointers for a second and make more focus to other arguments :)
As I said, my main argument was to reduce memory consumption. If it is desired to make this tools to be able to used in tiny embedded environments then it's important. Also an important argument is: the behavior of |
Hello, |
I'm not against the idea, just that there is more to think about it... the copy makes it easy to change the content without breaking the structure until we use the assemble visitor to put everything back in place. Also there are other similar copies in other part of the code than the 3 you address that probably should be addressed in the same issue. (meregion.go, section.go, rawregion.go, nvram.go and flash.go) |
I suppose when (and only then) we need to grow, we can perform a copy. |
Also, it seems, there's currently even actually no existing methods to extract offsets with a proper way :) |
nice catch, I had already forgotten about that one, but true solving this before would certainly help |
I agree that it's counterintuitive that if you don't call assemble, changes in the underlying data structure will not be reflected up to the top. The issue with not copying, and copying when you grow, is actually deeper. If we don't force a reassemble when you both either shrink or grow an element even by a few bytes, using the top level buffer results in an invalid image. Example: Suppose the FV contains 3 files and you shrink the first file by 10 bytes: I feel like adding support for not having to reassemble after every change would result in a lot of complications. We can get around the copy, if we strictly enforce that the parents buffers be truncated at the end of their headers, so that there's only one slice containing the data at one time, however you still have to call assemble/save after making your modifications, because this would then finally generate the top level binary you can reuse and flash. |
Again I would like to ask you, even if it takes a long while to explain, what are you trying to achieve? maybe we can make a custom visitor for you to make these modifications easily without relying on not calling assemble. |
Yeah. I guess you right. The
Well. It appears the approach with pointers was wrong. So I was have to use another. But still I need offsets (which is blocked by #164 ). Roughly speaking, my initial task is to perform a smart comparison of two firmwares images (the original one, and the one was extracted from a server) to see what could lead to the boot failure and why could that (image corruption) happen. So when I analyze the original image I find byte ranges which are important to the boot process. And since I try to detect bit flips I would prefer to just compare using the same byte ranges instead of re-parsing the damaged image (if a bit flipped in some "length" of whatever I will receive a wrong report). Anyway thank you for explaining about |
I have to return to this question. The service I implemented (based on fiano) consumes too much memory due to this copies. May be it worth to consider a special "read-only" mode to avoid this |
Hello.
I'm wondering if there's any specific reason of this copyings:
I've removed copying in my sandbox and everything still works. Also:
vs
So this copyings creates a lot of extra memory consumption for nothing.
Also in my case this copyings creates some obstacles, because I'm trying to calculate offsets by subtracting one pointer from another.(this point is not relevant anymore)So the question is would you accept a PR where I just remove this copyings?
The text was updated successfully, but these errors were encountered: